Search

just show me the code

Monday, May 11, 2009

Random Objects should be static

thanks to help from dotnetperls.

static Random _r = new Random();
static void F()
{
    // Use class-level Random so that when this
    // method is called many times, it still has
    // good Randoms.
    int n = _r.Next(12);
    // If this declared a local Random, it would
    // repeat itself.
    System.Console.WriteLine(n);
}

No comments:

Post a Comment

Contributors