Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
October 1st, 2003, 09:21 PM
 jut81
Junior Member

Join Date: Sep 2003
Posts: 3
Time spent in forums: < 1 sec
Reputation Power: 0
random number generation

hello,

i am stuck once again and need help understanding the linear congruential method
of pseudo random number generation.
This is what i do know

X(n+1) = (aX(n) + c) mod m, n >= 0, and X(0) = s

without specifying the values of the equation i will explain my dilema.

first of all it says x(0) =s but n is always greater than or equal to 0 so it will never be equal to zero because of n+1 right?

what is a seed in my equation it is s but to get the next rand value do i have to change s or leave it the same.

any hints, tips or questions welcome

thanks

#2
October 2nd, 2003, 12:10 AM
 Scorpions4ever
Banned ;)

Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,539
Time spent in forums: 2 Months 3 Days 9 h 15 m
Reputation Power: 4106
The problem you have is confusing math notation with array notation. n+1 refers to the (n+1)th generation of a
"random" number. Basically, what the equation translates to is:
"Use the previously generated number in an equation, to generate the next number". That's what n and n+1 refer to in the equation.

That's why the numbers are called pseudo-random.... if you know the original number, you can replicate the entire "random" number sequence. To prevent repeating a sequence, the trick is to choose a value for the initial seed (i.e a value for X(0)) that is sufficiently random and then use it to generate the subsequent numbers (X(1), X(2), X(3)... ) and so on. This is why many programs use the current time as the initial seed -- this isn't always the best seed to use for cryptographic purposes, but many programs use this.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

 Viewing: Dev Shed Forums > Programming Languages > C Programming > random number generation