Advertisement

writing a lcrng

Started by September 15, 2002 01:58 AM
1 comment, last by Shi-no-Mitsukai 22 years, 5 months ago
As the title implies, I'm currently trying to write a linear congruential random number generator, which looks like this: S(n+1) = ((a * S(n) + c) mod m) where m = (2^32) - 1 (as this is for 32-bit numbers) An article I've reading on the subject states that: b= a - 1 is a multiple of p, for every prime p that divides m. And the example they give uses 16 for m. That's all fine and good, but I'm really at a loss when it comes to testing this condition for all the primes up to (2^32) -1. I mean, that's a lot of primes, man! It's very likely that I'm missing something painfully obvios here, as my math skill as they say, suck. Any help would be greatly appreciated. Edit: typo. [edited by - Shi-no-Mitsukai on September 15, 2002 2:59:49 AM]
If this is for game development, then perhaps you can look for a simpler random number generator. Otherwise, this isn''t my area of expertise and I can''t advise you, and suggest you consider posting your question here:

http://mathforum.org/dr.math/

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
Advertisement
Thank you for the reply and link.

After bit of research, I''ve decided to go with a Multiply-with-Carry generator rather than the LCG.

If anybody''s interested, you can find more information on the various types of RNGs at http://cliodhna.cop.uop.edu/~hetrick/na_faq.html

-Shi

This topic is closed to new replies.

Advertisement