bebraw
11/9/2010 - 9:43 AM

gistfile1.txt

Problem Domain:
Drawing application, "splatter" brush. This brush generates a set of random dots (range and frequency given). It's imperative that the result may be reproduced later. Hence the need for a seed value. I get the seed value based on "dab" index (ie. 0, 1, 2, ...) and pass it on to the func that does the heavy lifting.

Random Problem:
Input:
S, seed value
N, amount of random numbers to generate
[0, 1], range of random number

Output:
[r1, r2, r3, ... rN], each rX belongs to [0, 1] and is picked "randomly"
 
Issue:
Generating one random number based on given seed is easy. My random number generator look like this (JS):
Math.random = function(seed) {
    // http://station.woj.com/2010/02/javascript-random-seed.html
    seed = defined(seed)? seed: new Date().getTime();

    return ((seed * 9301 + 49297) % 233280) / (233280.0);
}

The problem is that if I pick the result and pass it as a seed for the next item, it's going to produce a deterministic pattern. That's not something that looks particularly random. :)

Perhaps I need to shuffle the generated numbers, use multiple generators or something...