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: http://www.tkachenko.com/cgi-bin/mt-tb.cgi/340

TITLE: IndexingXPathNavigator reloaded URL: http://weblogs.asp.net/cazzu/archive/0001/01/01/116001.aspx IP: 66.129.67.203 BLOG NAME: eXtensible mind DATE: 11/14/2004 04:30:48 AM Read More

2 Comments

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.


Cheers,
Dimitre.

Leave a comment