Random numbers and loops
I have a method which generates random numbers to produce other object with those variables inside a for loop. However each cycle through the loop generates the same random numbers. Could anybody tell how to generate new random numbers for each cycle.
public Genome(int l)
{
length = l;
g = new Gene[length];
Random r = new Random();
for(int i = 0; i < length; i ++)
{
int x = r.Next(100);
int z = r.Next(100);
int a = r.Next(5);
int b = r.Next(10);
int c = r.Next(-3,3);
g[i] = new Gene(x,z,a,b,c);
g[i].CalcOutput();
}
}
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

jcity444Rank #3,217 · 446 pointsPosted Jan 9, 2005, 12:48 PM EST