c# random next code example

Example 1: c# random int

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

Example 2: C# random.Next error

public System.Random r = new System.Random();
public int guess1 = r.Next(0, 100000);

Example 3: obj random.next s#

Based on:

.NET 4.5

C# program that uses Random

using System;

class Program
{
    static void Main()
    {
	// ... Create new Random object.
	Random r = new Random();
	// ... Get three random numbers.
	//     Always 5, 6, 7, 8 or 9.
	Console.WriteLine(r.Next(5, 10));
	Console.WriteLine(r.Next(5, 10));
	Console.WriteLine(r.Next(5, 10));
    }
}

Output

5
7
6

Tags:

Misc Example