Skip to content

Instantly share code, notes, and snippets.

@samermurad
Created January 30, 2026 12:12
Show Gist options
  • Select an option

  • Save samermurad/a099a67b2f6e4527a8fcc5c997a4275f to your computer and use it in GitHub Desktop.

Select an option

Save samermurad/a099a67b2f6e4527a8fcc5c997a4275f to your computer and use it in GitHub Desktop.
Randomize a string chars using the mulberry32 deterministic randomness in JavaScript
function mulberry32(a) {
return function () {
let t = a += 0x6D2B79F5;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
const main = (str) => {
const rng = mulberry32(Math.random() * str.length + 1);
let numSet = new Set()
while (numSet.size < str.length) numSet.add(Math.round(rng() * (str.length - 1)));
let newStr = new Array(...numSet).map(n => str[n]).join('')
console.log(newStr)
return newStr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment