A random number within a specified range.
using System;
public class Example
{
public static void Main()
{
Random rnd = new Random();
Console.WriteLine("20 random integers from -100 to 100:");
for (int i = 1; i <= 20; i++)
{
Console.Write(rnd.Next(-100, 101));
}
Console.WriteLine("\n20 random integers from 1000 to 10000:");
for (int i = 1; i <= 20; i++)
{
Console.Write("{0,8}", rnd.Next(1000, 10001));
}
Console.WriteLine("\n20 random integers from 1 to 10:");
for (int i = 1; i <= 20; i++)
{
Console.Write("{0,6}", rnd.Next(1, 11));
}
}
}
Related examples in the same category