Options
All
  • Public
  • Public/Protected
  • All
Menu

Class JitterTrng

Wrapper for Jitterentropy True Random Number Generator

Hierarchy

  • JitterTrng

Index

Constructors

constructor

  • Create a new random number generator

    Parameters

    • Optional osr: number

      Controls oversampling, pass 1 to not oversample. Default is 1.

    • Optional flags: JitterentropyFlags

      Internal flags changes the bahaviour of the TRNG. Default is NONE.

    Returns JitterTrng

Properties

__inuse

__inuse: boolean

Flag that indicates current instance is in use. While this is true, anyone want to gather bytes or numbers from this instance will throws error. It is because the undely mechanism is not thread-safe, attempt to use the same undely collector instance in parallel will interrupt the state and may crashes the whole process.

Methods

generate

  • generate(byteCount: number): Buffer
  • Get a buffer that fills with random bytes.

    Parameters

    • byteCount: number

      How many bytes should be in the buffer.

    Returns Buffer

    A buffer fill with random bytes, but keep in mind that it still has chance that entropy does not enough to fufill the count requested.

generateAsync

  • generateAsync(byteCount: number): Promise<Buffer>
  • generateAsync(byteCount: number, callback: function): void
  • Parameters

    • byteCount: number

    Returns Promise<Buffer>

  • Parameters

    • byteCount: number
    • callback: function
        • (err: Error, result: Buffer): void
        • Parameters

          • err: Error
          • result: Buffer

          Returns void

    Returns void

random

  • random(): number
  • random(max: number): number
  • random(low: number, high: number, precision?: number): number
  • Generate a float-point number between 0 and 1.

    Returns number

  • Generate a float-point number between 0 and the value given.

    Parameters

    • max: number

      The number that generated number must not greater or equals to

    Returns number

  • Generate a float-point number between the values given.

    Parameters

    • low: number

      The number that generated number must not smaller to

    • high: number

      The number that generated number must not greater or equals to

    • Optional precision: number

      How many bytes will be used to get the number. Minimum is 1 (1 / 256 fragments), maximum is 6 (1 / 281,474,976,710,656 fragments), default is 6

    Returns number

randomAsync

  • randomAsync(): Promise<number>
  • randomAsync(max: number): Promise<number>
  • randomAsync(low: number, high: number, precision?: number): Promise<number>
  • randomAsync(callback: function): void
  • randomAsync(max: number, callback: function): void
  • randomAsync(low: number, high: number, callback: function): void
  • randomAsync(low: number, high: number, precision: number, callback: function): void
  • Returns Promise<number>

  • Parameters

    • max: number

    Returns Promise<number>

  • Parameters

    • low: number
    • high: number
    • Optional precision: number

    Returns Promise<number>

  • Parameters

    • callback: function
        • (err: Error, result: number): void
        • Parameters

          • err: Error
          • result: number

          Returns void

    Returns void

  • Parameters

    • max: number
    • callback: function
        • (err: Error, result: number): void
        • Parameters

          • err: Error
          • result: number

          Returns void

    Returns void

  • Parameters

    • low: number
    • high: number
    • callback: function
        • (err: Error, result: number): void
        • Parameters

          • err: Error
          • result: number

          Returns void

    Returns void

  • Parameters

    • low: number
    • high: number
    • precision: number
    • callback: function
        • (err: Error, result: number): void
        • Parameters

          • err: Error
          • result: number

          Returns void

    Returns void

randomInt

  • randomInt(max: number): number
  • randomInt(low: number, high: number): number
  • Generate an integer number between 0 and the value given.

    Parameters

    • max: number

      The number that generated number must not greater or equals to

    Returns number

  • Generate an integer number between the values given.

    Parameters

    • low: number

      The number that generated number must not smaller to

    • high: number

      The number that generated number must not greater or equals to

    Returns number

randomIntAsync

  • randomIntAsync(max: number): Promise<number>
  • randomIntAsync(low: number, high: number): Promise<number>
  • randomIntAsync(max: number, callback: function): void
  • randomIntAsync(low: number, high: number, callback: function): void
  • Parameters

    • max: number

    Returns Promise<number>

  • Parameters

    • low: number
    • high: number

    Returns Promise<number>

  • Parameters

    • max: number
    • callback: function
        • (err: Error, result: number): void
        • Parameters

          • err: Error
          • result: number

          Returns void

    Returns void

  • Parameters

    • low: number
    • high: number
    • callback: function
        • (err: Error, result: number): void
        • Parameters

          • err: Error
          • result: number

          Returns void

    Returns void

read

  • read(buf: Buffer, size?: number): number
  • Collect some random bytes from the Jitterentropy with provided buffer.

    Parameters

    • buf: Buffer

      The buffer object to contain the random bytes.

    • Optional size: number

      How many bytes to be collected, maximum is the buffer size.

    Returns number

    A number that indicates how many bytes has been collected to the buffer. Zero or negative values means something wrong is happened, please refer to mandoc Jitterentropy(3) for details.

readAsync

  • readAsync(buf: Buffer, size?: number): Promise<number>
  • readAsync(buf: Buffer, callback: function): void
  • readAsync(buf: Buffer, size: number, callback: function): void
  • Parameters

    • buf: Buffer
    • Optional size: number

    Returns Promise<number>

  • Parameters

    • buf: Buffer
    • callback: function
        • (err: Error, count: number): void
        • Parameters

          • err: Error
          • count: number

          Returns void

    Returns void

  • Parameters

    • buf: Buffer
    • size: number
    • callback: function
        • (err: Error, count: number): void
        • Parameters

          • err: Error
          • count: number

          Returns void

    Returns void

Generated using TypeDoc