Table of Contents

Class RandomGenerator

Namespace
LibSodium
Assembly
LibSodium.Net.dll

Static class for random number generation.

public static class RandomGenerator
Inheritance
RandomGenerator
Inherited Members

Fields

SeedLen

The length of the seed used for deterministic random byte generation.

public const int SeedLen = 32

Field Value

int

Methods

Close()

Closes the random number generator.

public static void Close()

Exceptions

LibSodiumException

Thrown when randombytes_close() fails.

Fill(Span<byte>)

Fills the specified buffer with random bytes.

public static void Fill(Span<byte> buffer)

Parameters

buffer Span<byte>

The buffer to fill with random bytes.

FillDeterministic(Span<byte>, ReadOnlySpan<byte>)

Fills the specified buffer with deterministic random bytes based on the provided seed. It produces the same sequence of random bytes for the same seed.

public static void FillDeterministic(Span<byte> buffer, ReadOnlySpan<byte> seed)

Parameters

buffer Span<byte>

The buffer to fill with deterministic random bytes.

seed ReadOnlySpan<byte>

The seed used for deterministic random byte generation.

Exceptions

ArgumentException

Thrown when the seed length is not equal to SeedLen.

GetUInt32()

Gets a random unsigned 32-bit integer.

public static uint GetUInt32()

Returns

uint

A random unsigned 32-bit integer.

GetUInt32(uint)

Gets a random unsigned 32-bit integer less than the specified upper bound.

public static uint GetUInt32(uint upperBound)

Parameters

upperBound uint

The upper bound (exclusive) for the random number.

Returns

uint

A random unsigned 32-bit integer less than upperBound.

Stir()

Stirs the random number generator to ensure randomness.

public static void Stir()