How to generate Random numbers in .NET


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:-

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)

Advertisements

Author: Imran Akram

A .NET/SharePoint Consultant and a political enthusiast who believes in putting the feet of the elected and/or unelected officials to fire in order to get good governance.

5 thoughts on “How to generate Random numbers in .NET”

    1. Thanks for dropping by, I think I’ve given the solution to your query in the last 2-3 lines of that same post. Please read that again.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s