Problem in System.Random

by Syed Aziz ur Rahman 4. May 2005 07:46

What will be your condition if you are not able to find the bug using debugging? Same happen to me and I spent nearly 2 hours in just catching the bug.

Actually my task was to generate a random time table based upon certian business rules. I used System.Random for this but after some time i come to know that it is not so random :) . When i debug the application, it generated a differnt random number but as soon as I Perss F5 in VS.net, thinking it is working fine, it starts giving repeated numbers. I was not even suspecting the Random class and continously checking the bug in business logic.

Suddenly i got a idea that may be the random generation is some how related to time. I check the random number generation seperately and problem was still there. I put the thread to sleep for 100 millisecond before next generation and walaaaa..it works.

I checked the documentation but it is not mentioned there the algo of generation is anyhow related to time. May be someone else know. If it is so, please let me know..




Powered by BlogEngine.NET
Original Design by Laptop Geek, Adapted by onesoft