1.0.0 • Published 8 months ago

@buff-beacon-project/rand-utils v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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.

1.0.0

8 months ago