how can i generate different number,it is generating the same number
Random rand = new Random(100000);
rand.Next();
how can i generate different number,it is generating the same number
Random rand = new Random(100000);
rand.Next();
Just remove the seed number in the constructor. This seed is essentially a number from which the random number list is generated. If you specify a constant number, your random number list will always be the same.
Random rand = new Random();
rand.Next();
Your specifying the same seed try this.
Random rand = new Random();
rand.Next();
This will use the default seed which is the time.
"Initializes a new instance of the Random class, using a time-dependent default seed value."
As per MSDN : http://msdn.microsoft.com/en-us/library/system.random.aspx
Re your comment above, how to generate a "random" number in a set range.
// Generate and display 5 random integers from 50 to 100.
Console.WriteLine("Five random integers between 50 and 100:");
Console.Write("{0,8:N0}", rand.Next(50, 101));
(Taken from MSDN link above) You can now generate whatever range you want.
Not sure exactly what you are after!
Random rand = new Random(Environment.TickCount);
rand.Next();
Random rand = new Random();
rand.Next(0,1000); // minimum = 0, maximum = 999
Random rand=new Random(DateTime.Now.Millisecond);
rand.Next();
This always works for me.