Monday, June 1, 2009

Generate Random Numbers - VB.NET or C#

Actually these are not exactly "true" random numbers. These are actually pseudo-random numbers, which means that they give you an illusion that they’re being generated randomly.

It’s very simple: There’s a class called System.Random. and the rest is as simple as this:-

In C#,

Random r = new Random(0);
int num = r.Next(0,999999);

in VB .NET,
dim r as Random = new Random(0)
dim num as Int = r.Next(0,999999)

No comments:

Post a Comment