Blockchain Commons Rand TypeScript Library - v1.0.0-alpha.13
    Preparing search index...

    Class SeededRandomNumberGenerator

    A random number generator that can be used as a source of deterministic pseudo-randomness for testing purposes.

    Uses the Xoshiro256** algorithm, which is the same algorithm used by rand_xoshiro in Rust. This ensures cross-platform compatibility with the Rust implementation.

    WARNING: This is NOT cryptographically secure and should only be used for testing purposes.

    Implements

    Index

    Constructors

    • Creates a new seeded random number generator.

      The seed should be a 256-bit value, represented as an array of 4 64-bit integers (as bigints). For the output distribution to look random, the seed should not have any obvious patterns, like all zeroes or all ones.

      This is not cryptographically secure, and should only be used for testing purposes.

      Parameters

      • seed: [bigint, bigint, bigint, bigint]

        Array of 4 64-bit unsigned integers as bigints

      Returns SeededRandomNumberGenerator

    Methods

    • Fills the given Uint8Array with random bytes.

      Note: This implementation matches the Rust behavior exactly - it uses one nextU64() call per byte (taking only the low byte), which matches the Swift version's behavior.

      Parameters

      • dest: Uint8Array

      Returns void

    • Returns a Uint8Array of random bytes of the given size.

      This might not be the most efficient implementation, but it works the same as the Swift version.

      Parameters

      • size: number

      Returns Uint8Array