@buff-beacon-project/rand-utils
v1.0.0
Published
Tools for consuming public randomness sources
Downloads
24
Readme
rand-utils
A set of utilities to make it easier to use random bit buffers.
Made for the CURBy Project
Installation
npm install @buff-beacon-project/rand-utils
Example
import { BitReader } from '@buff-beacon-project/rand-utils'
import { randomBytes } from 'crypto'
const rand = randomBytes(64)
const reader = BitReader.from(rand)
// random directions
const directions = ['up', 'down', 'left', 'right']
const randomDirections = reader.unfold((stream) =>
directions[stream.readBits(2, false)]
)
const list = Array.from(randomDirections)
// shuffled array
const arr = [0, 1, 2, 3, 4, 5, 6, 7]
const shuffled = reader.shuffled(arr)
Documentation
Found in the docs/ folder.