Skip to content

Documentation

Ricky Setiawan edited this page Jul 12, 2022 · 1 revision

Overview

All PRNG or RNG have implement interface IRNG.

All RNG's can be divided into 2, based on default output:

  • Random 32-bit
  • Random 64-bit

Here's the structure:

  • IRNG
    • Random
      • 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

  • ArgumentOutOfRangeException

    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.

  • ArgumentOutOfRangeException

    The requested output size can't lower than or equal to 0.

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

  • ArgumentOutOfRangeException

    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

  • ArgumentOutOfRangeException

    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

  • ArgumentOutOfRangeException

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

Choice(T[] items)

Return a random element from the given sets.

Parameter

  • items

    Set of items to choose.

Choice(T[] items, int select)

Return multiple random element from the given sets.

Parameter

  • items

    Set of items to choose.

  • select

    The desired amount to select.

Exception

  • ArgumentNullException
    • The items is null, empty or not initialized.
  • ArgumentOutOfRangeException
    • The number of elements to be retrieved is negative or less than 1.
    • The number of elements to be retrieved exceeds the items size.

Sample(T[] items, int k);

Select multiple distinct item from the sets.

Parameter

  • items

    Set of items to choose.

  • k

    The desired amount to select.

Exception

  • ArgumentNullException
    • The items is null, empty or not initialized.
  • ArgumentOutOfRangeException
    • The number of elements to be retrieved is negative or less than 1.
    • The number of elements to be retrieved exceeds the items size.

Shuffle(T[] items);

Shuffle items with Fisher-Yates shuffle.

Parameter

  • items

    Set of items to choose.

Exception

  • ArgumentNullException
    • The items is null, empty or not initialized.