Skip to content
Ricky Setiawan edited this page Nov 16, 2020 · 7 revisions

Overview

All PRNG or RNG have implement interface IRNG.

All RNG's can be divided into 2, based on internal state:

  • Random 32-bit
  • Random 64-bit

Here's the struture:

  • IRNG
    • Random32
      • rng 32 bit
    • Random64
      • rng 64 bit

Here's list of method you can use.

AlgorithmName()

Return the name of the algorithm this RNG implements.

Reseed()

Seed the internal state from System.Security.Cryptography.RNGCryptoServiceProvider.

If you want to manually seed the RNG or internal state, please create new instance. Because all RNG have different how they accept the seed, some accept 1 seed and some accept multiple seed.

NextBoolean()

Return a random C# true or C# false .

NextByte()

Return a random value from 0 to 255.

NextByte(byte lower, byte upper)

Return random number between lower and upper but the value must be in range 0 to 255.

Parameter

  • lower

    The lower bound or minimal value to generate.

  • upper

    The upper bound or maximal value to generate.

Exception

  • ArgumentException

    The lower bound must not be greater than or equal to the upper bound.

NextBytes(int length)

Return array of bytes with length as requested.

Parameter

  • length

    Requested size or length of array.

NextInt()

Return a 32-bit unsigned integer.

NextInt(uint lower, uint upper)

Return random number between lower and upper but the value must be in range 0 to 4,294,967,295.

Parameter

  • lower

    The lower bound or minimal value to generate.

  • upper

    The upper bound or maximal value to generate.

Exception

  • ArgumentException

    The lower bound must not be greater than or equal to the upper bound.

NextLong()

Return a 64-bit unsigned integer.

NextLong(ulong lower, ulong upper)

Return random number between lower and upper but the value must be in range 0 to 18,446,744,073,709,551,615.

Parameter

  • lower

    The lower bound or minimal value to generate.

  • upper

    The upper bound or maximal value to generate.

Exception

  • ArgumentException

    The lower bound must not be greater than or equal to the upper bound.

NextDouble()

Return a 64-bit floating point.

NextDouble(double lower, double upper)

Return random number between lower and upper.

Parameter

  • lower

    The lower bound or minimal value to generate.

  • upper

    The upper bound or maximal value to generate.

Exception

  • ArgumentException

    The lower bound must not be greater than or equal to the upper bound.

Extra Method

This method only exist in Random32 and Random64 only

Clone this wiki locally