Genetrate Random Integer

Favourite

Extended C# function to genetrate random integer.

Code Snippet

public static Int32 NextInt32(this Random rnd)
{
    var buffer = new byte[sizeof(Int32)];
    rnd.NextBytes(buffer);
    return BitConverter.ToInt32(buffer, 0);
}

Sample Usage

Random rnd = new Random();
int intRnd = rnd.NextInt32();


author's photo

Author : Si Thu

I am just a normal programmer. Cool, quiet and simple person. Love to write code without pressure. Most of the time, I am reading, writing, watching movie or surfing the web.

COMMENTS
blog comments powered by Disqus