Skip to main content

Rng

caution

This service is rc and may change in the future.

Generates random numbers using entropy sourced from physical processes.

This typically uses a cryptographical pseudo-random number generator (for example Fortuna), which is periodically re-seeded with entropy coming from some hardware source.

import { Rng } from "@devicescript/core"

const rng = new Rng()

Registers

random

A register that returns a 64 bytes random buffer on every request. This never blocks for a long time. If you need additional random bytes, keep querying the register.

  • type: Register<Buffer> (packing format b)

  • track incoming values

import { Rng } from "@devicescript/core"

const rng = new Rng()
// ...
rng.random.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

variant

The type of algorithm/technique used to generate the number. Quantum refers to dedicated hardware device generating random noise due to quantum effects. ADCNoise is the noise from quick readings of analog-digital converter, which reads temperature of the MCU or some floating pin. WebCrypto refers is used in simulators, where the source of randomness comes from an advanced operating system.

  • type: Register<number> (packing format u8)

  • optional: this register may not be implemented

  • constant: the register value will not change (until the next reset)

  • read only

import { Rng } from "@devicescript/core"

const rng = new Rng()
// ...
const value = await rng.variant.read()
note

write and read will block until a server is bound to the client.