Random numbers not working 
Author Message
 Random numbers not working

I'm trying to generate random numbers from 1000 - 9999. Here is the code but
it always generates 0. What am i doing wrong. thanks

int NewKey;
Random r = new Random();
NewKey = r.Next(1000,9999);



Wed, 25 Feb 2004 01:07:24 GMT  
 Random numbers not working
It looks like you're doing everything right (from the code you supplied...).
The default constructor you used uses a time dependent default seed value.
And the Next method you used allows you to specify the range (min/max pair).
The only thing to be careful about is if your application runs on a fast
computer the system clock might not have time to change between invocations
of this constructor; thus the seed value might be the same for different
instances of Random. But none of that explains why you always get 0. Can you
provide more detail about the context of your code and why you feel you
always get 0?

Darren Shou


Quote:
> I'm trying to generate random numbers from 1000 - 9999. Here is the code
but
> it always generates 0. What am i doing wrong. thanks

> int NewKey;
> Random r = new Random();
> NewKey = r.Next(1000,9999);



Wed, 25 Feb 2004 04:46:16 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Random number not so random

2. working with random numbers

3. How NOT to write a random number generator

4. why aren't my random numbers random ?

5. random number generator random() questionable!!!?

6. counting number of lines in a file(not home work)

7. Number of Copies Not Working

8. C++/ATL/ADO - Intellisense not working (statement completion options) not working

9. set seed of random number

10. any good methods for generating psuedo random numbers

11. a real random number generator?

12. random number generater

 

 
Powered by phpBB® Forum Software