Friday, July 31, 2009

C# Code, Help on Random/Next?

Random randNum = new Random();


randNum.Next(100);





still learning, When this runs, I get 0 as an answer everytime.?


I have randNum being declaired "static int radNum"

C# Code, Help on Random/Next?
Dude, you have to set it to something. Your object of class Random is just a random number *generator*. You're trying to reuse the same variable name.





Random r = new Random();


int randNum = r.Next(100);
Reply:the problem might be you aren't using any seed value. Set the seed value and than try the same again. Also use the variable to store the randNum.Next value. Keep chaging the seed value.








int seed = DateTime.Now.MilliSecond;


Random randNum = new Random(seed);


int a = randNum.Next(100);


No comments:

Post a Comment