squares 0.1.1

A Counter-RNG faster than Philox
Documentation
  • Coverage
  • 31.58%
    6 out of 19 items documented1 out of 1 items with examples
  • Size
  • Source code size: 29.09 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.37 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • wbrickner

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):

fn time per core
u32 1.29ns 3.10 GB/s
u64 1.65ns 4.85 GB/s
key 24.5ns 40.8 M/s

License

MIT OR Apache-2.0