Skip to content

Instantly share code, notes, and snippets.

@helloimalastair
Last active May 7, 2022 21:24
Show Gist options
  • Save helloimalastair/b37d949bc2547ad016374310ad9f16db to your computer and use it in GitHub Desktop.
Save helloimalastair/b37d949bc2547ad016374310ad9f16db to your computer and use it in GitHub Desktop.
Revision of Erisa's Phonetic Generator. Utilizes Alastair's BetterRand
// Revision of Erisa's Phonetic Generator(https://github.com/Erisa/starbin/blob/b8a333b781a893dcae60c4fb2638d34e63c6f568/index.js#L38). Utilizes Alastair's BetterRand(https://gist.github.com/helloimalastair/9143e9d43f4a641b23ebddfa11cefeff)
const BetterRand = async t=>{const n=new Int32Array(20),r=(await(await fetch("https://drand.cloudflare.com/public/latest")).json()).signature;crypto.getRandomValues(n);const a=function(t){for(var n=0,r=1779033703^t.length;n<t.length;n++)r=(r=Math.imul(r^t.charCodeAt(n),3432918353))<<13|r>>>19;return function(){return r=Math.imul(r^r>>>16,2246822507),r=Math.imul(r^r>>>13,3266489909),(r^=r>>>16)>>>0}}((void 0===t?null:t.toString())+crypto.toString()+r+Date.now());return o=a(),e=a(),u=a(),c=a(),function(){var t=e<<9,n=5*o;return c^=e,e^=u^=o,o^=c,u^=t,c=c<<11|c>>>21,((n=9*(n<<7|n>>>25))>>>0)/4294967296};var o,e,u,c};
const randOf = (collection, rand) => () => collection[Math.floor(rand() * collection.length)];
async function generateId() {
const rand = await BetterRand("This Seed Is Very Secure, and not at all a sentence that is easy to guess."),
randVowel = randOf("aeiou", rand),
randConsonant = randOf("bcdfghjklmnpqrstvwxyz", rand);
let id = "";
const start = Math.round(rand());
for (let i = 0; i < 10; i++) id += (i % 2 == start) ? randConsonant() : randVowel();
return id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment