Random numbers and loops

Jan 8 2005 6:35 AM
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(); } }

Answers (1)