Imprinting on "randomness"

| 2 Comments | 1 TrackBack

Well, that's just a simple level 100 quiz aiming to imprint "standard random number generators are not really random" program to those who still lack it. What will produce the following C# snippet?

System.Random rnd = new System.Random(12345);
System.Random rnd2 = new System.Random(12345);
for (int i=0; i<1000; i++)            
if (rnd.Next() != rnd2.Next())
    Console.WriteLine("Truly random!");

Related Blog Posts

1 TrackBack

TrackBack URL:

TITLE: IndexingXPathNavigator reloaded URL: IP: BLOG NAME: eXtensible mind DATE: 11/14/2004 04:30:48 AM Read More


A more subtle variation occurs if you create an instance of a System.Random on each of a pool of threads at startup. If you're not careful they can all start with the same seed (based on the clock) and produce identical sequences. Not usually what you mean to do ;)

The result will be the empty string.

It is wellknown that if you start from the same seed you'll get the same sequence of numbers.


Leave a comment