Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @stablelib/random

Index

Variables

defaultRandomSource: SystemRandomSource = ...

Functions

  • randomBytes(length: number, prng?: RandomSource): Uint8Array
  • randomString(length: number, charset?: string, prng?: RandomSource): string
  • Returns a uniform random string of the given length with characters from the given charset.

    Charset must not have more than 256 characters.

    Default charset generates case-sensitive alphanumeric strings (0-9, A-Z, a-z).

    Parameters

    • length: number
    • charset: string = ALPHANUMERIC
    • prng: RandomSource = defaultRandomSource

    Returns string

  • randomStringForEntropy(bits: number, charset?: string, prng?: RandomSource): string
  • Returns uniform random string containing at least the given number of bits of entropy.

    For example, randomStringForEntropy(128) will return a 22-character alphanumeric string, while randomStringForEntropy(128, "0123456789") will return a 39-character numeric string, both will contain at least 128 bits of entropy.

    Default charset generates case-sensitive alphanumeric strings (0-9, A-Z, a-z).

    Parameters

    • bits: number
    • charset: string = ALPHANUMERIC
    • prng: RandomSource = defaultRandomSource

    Returns string

Generated using TypeDoc