Skip to content

Instantly share code, notes, and snippets.

@balanza
Created April 22, 2024 13:57
Show Gist options
  • Save balanza/40339e5a5827c12b703fc37812544db3 to your computer and use it in GitHub Desktop.
Save balanza/40339e5a5827c12b703fc37812544db3 to your computer and use it in GitHub Desktop.
Prove random UUID distribution upon the character space
const uuid = require("node:crypto").randomUUID;
const m = new Map();
const N = 1e7;
for (let i = 0; i < N; i++) {
const k = uuid().split("").reverse()[0];
if (m.has(k)) {
m.set(k, m.get(k) + 1);
} else {
m.set(k, 1);
}
}
const avg = N / m.size / N;
const l = [];
m.forEach((v, k) => {
const r = v / N;
l.push(r - avg);
});
const abs = [...l].map((v) => Math.abs(v)).sort((a, b) => a - b);
console.log(`min divergence: ${abs[0]}`);
console.log(`max divergence: ${abs[abs.length - 1]}`);
console.log(`expected average: ${avg}`);
console.log(`N = ${N}`);
console.log(`size = ${m.size}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment