# Random number in range generation.

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 03-04-2008
matsp
Quote:

Originally Posted by hebali
My M and N are negative number:
M = -10, N = -400
how does this affect the equation?

Aside from the range being 390, it shouldn't make any difference. In my test-case it works just fine.

What sequence are you getting?

--
Mats
• 03-04-2008
hk_mp5kpdw
For that range, I tried that code generating 1000 numbers instead of just 25 and got 17 repeats... 100 numbers and I got 1 repeat... 25 numbers (run 5 times) and not a single repeat any of those times.
• 03-04-2008
hebali
Hey,
I've also been doing some tests on it and I wonder if anyone could speak to something I noticed:
If I had the program generate only 1 random number, and then I ran that program a few times, there was a higher incidence of repeating than if I had the program generate several random numbers all in one go. Does this make sense given the algorithm?
Thanks.
• 03-04-2008
matsp
Quote:

Originally Posted by hebali
Hey,
I've also been doing some tests on it and I wonder if anyone could speak to something I noticed:
If I had the program generate only 1 random number, and then I ran that program a few times, there was a higher incidence of repeating than if I had the program generate several random numbers all in one go. Does this make sense given the algorithm?
Thanks.

Sure, it makes sense given that the change in the original seed given to srand() is "similar", which leads to a more likely incidence of the same number [if time is measured in seconds, then two calls within the same second will give the same seed -> same random number].

--
Mats
• 03-04-2008
hebali
gotcha. makes sense. thanks.
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12