Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Random

Assembly: System.Runtime

Inheritance: object → Random

Represents a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness.

Methods

public string
GetHexString​(int stringLength, bool lowercase = False)
stringLength The length of string to create.
lowercase <para> <see langword="true" /> if the hexadecimal characters should be lowercase; <see langword="false" /> if they should be uppercase.</para> <para>The default is <see langword="false" />.</para>
Returns A string populated with random hexadecimal characters.
Creates a string filled with random hexadecimal characters.
public void
GetHexString​(Span`1 destination, bool lowercase = False)
public T[]
GetItems​(ReadOnlySpan`1 choices, int length)
public void
GetItems​(ReadOnlySpan`1 choices, Span`1 destination)
public T[]
GetItems​(T[] choices, int length)
public string
GetString​(ReadOnlySpan`1 choices, int length)
public int
Next​()
Returns A 32-bit signed integer that is greater than or equal to 0 and less than <see cref="F:System.Int32.MaxValue">Int32.MaxValue</see> .
Returns a non-negative random integer.
public int
Next​(int maxValue)
maxValue The exclusive upper bound of the random number to be generated. <paramref name="maxValue" /> must be greater than or equal to 0.
Returns A 32-bit signed integer that is greater than or equal to 0, and less than <paramref name="maxValue" /> ; that is, the range of return values ordinarily includes 0 but not <paramref name="maxValue" /> . However, if <paramref name="maxValue" /> equals 0, 0 is returned.
Returns a non-negative random integer that is less than the specified maximum.
public int
Next​(int minValue, int maxValue)
minValue The inclusive lower bound of the random number returned.
maxValue The exclusive upper bound of the random number returned. <paramref name="maxValue" /> must be greater than or equal to <paramref name="minValue" /> .
Returns A 32-bit signed integer greater than or equal to <paramref name="minValue" /> and less than <paramref name="maxValue" /> ; that is, the range of return values includes <paramref name="minValue" /> but not <paramref name="maxValue" /> . If <paramref name="minValue" /> equals <paramref name="maxValue" /> , <paramref name="minValue" /> is returned.
Returns a random integer that is within a specified range.
public void
NextBytes​(byte[] buffer)
buffer The array to be filled with random numbers.
Fills the elements of a specified array of bytes with random numbers.
public void
NextBytes​(Span`1 buffer)
public double
NextDouble​()
Returns A double-precision floating point number that is greater than or equal to 0.0, and less than 1.0.
Returns a random floating-point number that is greater than or equal to 0.0, and less than 1.0.
public long
NextInt64​()
Returns A 64-bit signed integer that is greater than or equal to 0 and less than <see cref="F:System.Int64.MaxValue">Int64.MaxValue</see> .
Returns a non-negative random integer.
public long
NextInt64​(long maxValue)
maxValue The exclusive upper bound of the random number to be generated. <paramref name="maxValue" /> must be greater than or equal to 0.
Returns A 64-bit signed integer that is greater than or equal to 0, and less than <paramref name="maxValue" /> ; that is, the range of return values ordinarily includes 0 but not <paramref name="maxValue" /> . However, if <paramref name="maxValue" /> equals 0, <paramref name="maxValue" /> is returned.
Returns a non-negative random integer that is less than the specified maximum.
public long
NextInt64​(long minValue, long maxValue)
minValue The inclusive lower bound of the random number returned.
maxValue The exclusive upper bound of the random number returned. <paramref name="maxValue" /> must be greater than or equal to <paramref name="minValue" /> .
Returns A 64-bit signed integer greater than or equal to <paramref name="minValue" /> and less than <paramref name="maxValue" /> ; that is, the range of return values includes <paramref name="minValue" /> but not <paramref name="maxValue" /> . If minValue equals <paramref name="maxValue" /> , <paramref name="minValue" /> is returned.
Returns a random integer that is within a specified range.
public Single
NextSingle​()
Returns A single-precision floating point number that is greater than or equal to 0.0, and less than 1.0.
Returns a random floating-point number that is greater than or equal to 0.0, and less than 1.0.
protected double
Sample​()
Returns A double-precision floating point number that is greater than or equal to 0.0, and less than 1.0.
Returns a random floating-point number between 0.0 and 1.0.
public void
Shuffle​(Span`1 values)
public void
Shuffle​(T[] values)
public bool
Equals​(object obj)
Inherited from object
obj The object to compare with the current object.
Returns <see langword="true" /> if the specified object is equal to the current object; otherwise, <see langword="false" /> .
Determines whether the specified object is equal to the current object.
protected void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public int
GetHashCode​()
Inherited from object
Returns A hash code for the current object.
Serves as the default hash function.
public Type
GetType​()
Inherited from object
Returns The exact runtime type of the current instance.
Gets the <see cref="T:System.Type" /> of the current instance.
protected object
MemberwiseClone​()
Inherited from object
Returns A shallow copy of the current <see cref="T:System.Object" /> .
Creates a shallow copy of the current <see cref="T:System.Object" /> .
public string
ToString​()
Inherited from object
Returns A string that represents the current object.
Returns a string that represents the current object.