Tag Archives: random value

Generate a random number (or byte array)

To generate a random number use the System.Random.Random class

The numbers generated are pseudo random. Typically, using the same seed generates the same value sequences.

The seed can be set in the constructor. If none is set, a time dependent seed is used which should generate more or less random values.

To get a value call the method Next

int value = rand.Next();

or within range 0 – 255

int value = rand.Next(255);

or between 100 and 200

int value = rand.Next(100, 200);

a double between 0.0 and 1.0

double value = rand.NextDouble();

Or a byte buffer

Byte data = new Byte[100];

Lastest update in November 2015, inital post in May 2011