C# Random Random()

Description

Random Random() initializes a new instance of the Random class, using a time-dependent default seed value.

Syntax

Random.Random() has the following syntax.


public Random()

Example

The following example uses the default constructor to instantiate three Random objects and displays a sequence of five random integers for each.


//from  w w  w  .j a va  2s. c o  m
using System;
using System.Threading;

public class RandomNumbers
{
   public static void Main()
   {
      Random rand = new Random();

      byte[] values = new byte[5];
      rand.NextBytes(values);
      foreach (byte value in values)
         Console.Write("{0, 5}", value);
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version