A Flash Developer Resource Site

# Thread: pseudo random number generator

1. ## pseudo random number generator

I need a simple random number generator, which I can set up to give the the same sequence twice, by initialising a seed.

It doesn't need top be too random in fact - a sequence length of a few hundred would suffice. But I would like it to be very simple to implement - one line of actionscript if possible.

If anyone has the book "The Art of Computer Science: Seminumerical Algorithms" There are some parameters for a (ax+b) mod c generator in there. (At least I think that's it? - years since I saw this book).

Or if anyone has an alternative algorithm?

2. Hey brutfood!

I'm assuming that you would be the 'Ryan' who emailed me about this, if not, it's just a strange coincidence ... I checked my Flash 5 archives, and found a file that I worked on long ago that uses 6 prime numbers within the algorithm, combining with 3 input numbers and a range value to compute an array of pseudo-random numbers.

I've updated the file somewhat to Flash MX standards, but so far I haven't located any information as to the source for the algorithm I've used (I think it's a progression of the 'linear congruential pseudorandom number generator' example that you cited) ... I'm still looking, however, and I'll post it if I find it.

I believe that it will suit your needs (although it's way more than 1 line of code!), creating an array of integers between 1 and some value that the 'range' input controls ... that value is based on the significant digits (and/or +1 sigdig, depending on value) of the range input. Play with the input to figure out for yourself what the heck I'm talking about!

seedPseudoRandom0.1.1 .swf .fla

Sorry to be so vague, but I can't recall the research I did on this ... it will no doubt come to me in my dreams tonight!

Richard

3. Thanks for that!

I'm not Ryan who emailed - so it must be a strange coincidence then

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap