Crate squares

Source
Expand description

§Squares RNG

Implementation of the Squares CBRNG

  • Counter-based RNGs are non-serial: you can jump to any index in the RNG sequence. This is especially useful in parallel / distributed contexts

  • Squares is the fastest known CBRNG, and has higher quality than Philox at 2x speed

  • Squares is still slower than serial RNGs

  • Provides 2^64 outputs per key

  • This crate is no_std, and all functions are const

§Example

CBRNGs are stateless. A key is like a seed.

let r32 = squares::u32(key, idx);
let r64 = squares::u64(key, idx);

§Admissible Keys

Squares keys are not arbitrary! Many bit patterns can lead to poor output quality.

The key function makes an admissible Squares key from a “seed” index, which has no restrictions.

let key = squares::key(239482304);

For a manual key, see Key::checked and Key::unchecked.

§rand Compatibility

Enable the rand feature to expose Squares, an RNG struct compatible with the rand crates.

§Approximate Throughput

Results will vary. On my laptop (M1 Max):

fntimeper core
u321.29ns3.10 GB/s
u641.65ns4.85 GB/s
key24.5ns40.8 M/s

§License

MIT OR Apache-2.0

Structs§

Key
Holds an admissible Squares key

Enums§

Inadmissible
Represents a broken key rule

Functions§

key
Deterministically produces a high entropy admissible key determined by index. Think of index as your “seed”, which determines the key.
u32
Produces a u32 of random bits. Less efficient than [squares::u64].
u64
Produces a u64 of random bits.