Possible Duplicate:
Why does it appear that my random number generator isn't random in C#?
Dear friends
I want to generate 4 random number between 1 – 55 ,but the problem is that most of the time I receive 2 number same 🙁 for example the generated number is 2 2 5 9 or 11 11 22 22!
I dont know why?
I use :
Random random = new Random();
return random.Next(min, max);
for generating my random number. I put them in a While for repeating 4 times. Any Idea?Would u help me plz?
You should create just one Random() object and reuse it instead of creating a new one for each random number you generate.
The reason is that every time you create a new Random object it seeds itself from the current time. If you create multiple Random objects within a short period of time then then they will seed with the same time, and so they will generate the same numbers.