"Maziar Aflatoun" <ma***@rogers.com> wrote in message

news:QC*******************@news04.bloor.is.net.cab le.rogers.com...

Hi everyone,

I have the following code in my class method

TheSeed = (int)DateTime.Now.Ticks;

Random rndNum = new Random(TheSeed);
The above should be done one time only. The following lines should be

iterated. RandNum = rndNum.Next(0, TotalRows);

Debug.WriteLine("RandNum:" + RandNum + " Low:0 " + "High:" +
TotalRows);

Does anyone know why C# Random function is generating more 1,0,2,3 much
more frequently than 4,5,6,7,8?

For starters your random seed doesn't look to be very random. Are you

creating/destroying the rndNum object for every number? If so then you

aren't making use of a randomizing algorithm. Every number will be the

first in the sequence based on the supplied seed. If you call it twice with

the same seed (i.e. within one tick) you will get the same number. You

might notice your numbers repeat often, a sure sign you are within one tick

on two successive iterations (this would cause a failure on a runs test for

randomness.) The distribution of random numbers over your range will be

very poor (as you have seen) and a chi-square statistical test won't do too

well either to test your set of numbers for a large number of iterations.

Try generating the same sequence, but only calling the .Next method inside

your loop and preserve the rndNum object without resetting the seed each

time.

Jack Peacock