Bachalo
Bachalo

Reputation: 7219

actionscript-creating a consistent 'random' value

Can anyone point me to an example of creating consistent random values in actionscript. I assume this would, be by using a consistent seed value

Upvotes: 3

Views: 130

Answers (1)

Kejml
Kejml

Reputation: 2204

I think there is no way doing this using standard Math.random(). But you can write your own generator. Linear congruential generators (like Randu) are fast, and really simple to implement (just few lines of code), but they are not perfect. For games, it is fine, but for some scientific calculations (I don't expect you are doing some in actionscript), you may encounter problems. If you are interested, read for example http://en.wikipedia.org/wiki/Linear_congruential_generator#Advantages_and_disadvantages_of_LCGs

Or I found this implementation of Mersenne Twister generator: http://web.archive.org/web/20080218041026/http://www.devslash.com/?p=97 It is little slower, but it should be more robust than LCG generators.

Upvotes: 7

Related Questions