Randomness
I've always been curious about so called random number generators. Briefly my curiosity was transformed into virulent skepticism. I was working on a genetic algorithm and noticed some sub-optimal behavior so I went in to the code and printed the output of a random Boolean generator:
false false false false false false false
gee whiz! I thought, that doesn't look random. So I isolated a random Boolean generator and let it spit out some values:
false false true false true
That certainly seemed random to me so I ran a few more tests to be sure. I decided to create a whole battery of random Boolean generators and examine their output.
false false true false true
false false true false true
false false true false true
false false true false true
false false true false true
false false true false true
false false true false true
About now a little madness was creeping into my soul as I stared at the monitor. It turned out, however, that the problem was fairly straight forward. The random Boolean generator has a constant, unchanging default seed from which it generates random sequences of trues and falses. I, however, was not repeatedly using the same Boolean generator, but creating lots of independent generators that all had the same default seed.
The solution was to put in a different seed every time, and that was the key word, "time". I grabbed the time in milliseconds (System.currentTimeMillis()) and plugged it in to the generator to use as a seed. Suddenly everything was much more pleasantly random.
Believe it or not I got a performance boost as high as 40% out of my genetic algorithm with marginally slower, but more-truly random numbers.
Other tags this item is listed under include: smartamusement,
THE WALL: Read and post comments here.
Comments may be deleted at any time for any reason. Please be polite.
Post a response.
Please note: no html or javascript of any kind is allowed in a post. It is automatically stripped out. Sorry for any inconvenience.


