Thursday, December 10, 2009

Randomization

public int randomize(int maxValue)
{
    return ((((int)DateTime.Now.DayOfWeek) + DateTime.Now.Second + DateTime.Now.Millisecond + DateTime.Now.Second) % maxValue);
}


I was touring through some of the base libraries that we use in our code at work and had always wondered why we didn't use the built-in Random functions.  We were always told that the randomize function was better because there was a "flaw" in .NET that made the random function produce the same number every time it was used.  This function was the "official" solution to that problem.

0 comments:

Post a Comment