Thread: Random number in range generation.

1. 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

2. 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.

3. 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.

4. 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

5. gotcha. makes sense. thanks.

Popular pages Recent additions