How to choose a random numer in C# code example

Example 1: c# random int

Random rnd = new Random();
int number  = rnd.Next(1, 10);

Example 2: c# random generator

// One string will be randomly picked and displayed 
Random rnd = new Random();
string[] secOptions = {"string one", "string two", "string three"};
int randomNuber = rnd.Next(0, 3);
string secText = secOptions[randomNuber];
Console.WriteLine(secText);

Example 3: c# generate random int in range

Random r = new Random();
int rInt = r.Next(0, 100); //for ints
int range = 100;
double rDouble = r.NextDouble()* range; //for doubles

Example 4: c# random

Random rnd = new Random();
Byte[] bytes = new Byte[20];
rnd.NextBytes(bytes);
for (int ctr = 1; ctr <= bytes.Length; ctr++) {
   Console.Write("{0,3}   ", bytes[ctr - 1]);
   if (ctr % 10 == 0) Console.WriteLine();
}

// The example displays output like the following:
//       141    48   189    66   134   212   211    71   161    56
//       181   166   220   133     9   252   222    57    62    62