This content has been marked as final. Show 5 replies
After some quick testing, I can't see any noticeable repetition in the numbers. Can you confirm that the numbers coming out of random() are actually repeating? Are you keeping enough digits from the numbers?
Here is everything I've learned about this:
For reference, the puzzle game is: http://actionpuzzles.com/Reassembler.html
I play the game in a browserless flash player on my own pc frequently. I started noticing the problem when it seemed like I was seeing the same starting word (chosen from a list of more than 1000) with the same encoding from time to time. I traced the random number used to pick the word and the results seemed ok - a reasonable distribution from 0 to 1000. Note that whenever I use random() turn it into an int with something like: "ran = Math.floor(Math.random()*range)" where range covers the values I need.
Besides seeing the same word, I get the same encoding, which means that I am getting the same sequence of random integers over a run of at least 65 calls. I'm looking at the integers I use, not the reals that random() provides, but I don't think that makes any difference.
I am not sure, but I think this problem only happens with the first game after I start the flash player.
I really don't have to background to prove anything about the randomness of the random() function, but unless I get some help with this I will have to write my own function, or change the random() result based on the clock, or something.
Thanks for your assistance, Joe Casey
You will have to write some kind of seed of your own. Use flash.utils.getTimer() * the random(). Or UTC timestamp from a new Date().
Most random generators are only psuedo random. But most languages also provide seed functionality to help get around it. Later,
Ok, I was able to reproduce the problem by repeatedly running a test swf file in a standalone player. After a bunch of runs, I noticed that there were maybe only 5 or 6 "random" sequences generated at startup. It's probably not a bug in the random() method itself, it's just that they haven't provided a convenient seeding method (which could be considered a bug). I think Renaun's advice is the way to go.
Ok, will do.
It might be a good idea to add some discussion to the random() description in the Flex Reference.
Thanks, Renaun and Inlineblue.