.NET Random Number / Date / Decimal / File Generator

How to generate a random value using System.Random

The following are examples of random value generators:

public Random _rd = new Random();

public List GetRandomFiles(string[] filesList, int numberOfFiles)

List files = new List();
for (int i = 0; i < numberOfFiles; i++)
int index = _rd.Next(0, filesList.Length);
return files;

public string GetRandomDate()

DateTime start = new DateTime(1995, 1, 1);
int range = ((TimeSpan)(DateTime.Today - start)).Days;
return string.Format("{0:MM/dd/yyyy}", start.AddDays(_rd.Next(range)));

public string GetRandomNumber()

int rdNum = _rd.Next(-2147483648, 2147483647);
return Convert.ToString(rdNum);

public string GetRandomDecimal()

double rdDecimal = _rd.NextDouble();
return string.Format("{0:0.00}", rdDecimal);

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