A
Anil Gupte
I had someone write a random number generator in C# (I am more of a VB
programmer) and they came up with the following:
public string GetRand(int count)
{
string number = "";
for (int i=0; i<count; i++)
{
Random Rnd = new Random();
number = number+Convert.ToString(Rnd.Next(0,9));
}
return number;
}
I want to return a string of digits where each each string is unique.
Unfrotunately, this function is retrning strings like "11111111" and
"44444444" and so on. This means the seed is not getting initialized on
each interation but only on the first one. Now in VB, I would have put the
Randomize() satement inside the loop so a new seed is innitialized. Is
there an equivalent in C#? Is there a better way to do what we need?
Thanx,
programmer) and they came up with the following:
public string GetRand(int count)
{
string number = "";
for (int i=0; i<count; i++)
{
Random Rnd = new Random();
number = number+Convert.ToString(Rnd.Next(0,9));
}
return number;
}
I want to return a string of digits where each each string is unique.
Unfrotunately, this function is retrning strings like "11111111" and
"44444444" and so on. This means the seed is not getting initialized on
each interation but only on the first one. Now in VB, I would have put the
Randomize() satement inside the loop so a new seed is innitialized. Is
there an equivalent in C#? Is there a better way to do what we need?
Thanx,