JSPM

@buff-beacon-project/rand-utils

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 8
  • Score
    100M100P100Q22014F
  • License MIT

Tools for consuming public randomness sources

Package Exports

  • @buff-beacon-project/rand-utils

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.