Skip to content

Instantly share code, notes, and snippets.

View jeremybradbury's full-sized avatar
🎹
Making music

Jeremy Bradbury jeremybradbury

🎹
Making music
  • Portland, OR
  • 03:33 (UTC -07:00)
View GitHub Profile
@jeremybradbury
jeremybradbury / shuffle.node.js
Last active May 18, 2024 07:27
Fisher Yates Shuffle
// Crypto PseudoRandom Shuffle: one right way to randomize, esp for gaming
// https://replit.com/@jeremybradbury/CSPRNG-Fisher-Yeats-Shuffle
// NodeJS - CJS version (backward comaptible)
const crypto = require("crypto");
// the secret sauce
const getRndInt = (bytes) =>
parseFloat(
parseFloat(crypto.randomBytes(bytes).toString("hex"), 16).toString(10),
10