Skip to content

Instantly share code, notes, and snippets.

@TokenChingy
Created March 22, 2019 05:24
Show Gist options
  • Save TokenChingy/91459ffb1e88421c1b3ed086c9de3ce9 to your computer and use it in GitHub Desktop.
Save TokenChingy/91459ffb1e88421c1b3ed086c9de3ce9 to your computer and use it in GitHub Desktop.
Seeded random color generator in Javascript.
function seededRandomColor(seed) {
function LCG(s) {
return (Math.imul(741103597, s) >>> 0) / 2 ** 32;
}
const symbols = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += symbols[Math.round(LCG(seed + i) * 16)];
}
return color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment