From: Ardis Lu Date: Mon, 5 Jun 2023 07:22:46 +0000 (-0700) Subject: Simplify rng X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=b894698e94573e0c146ccbc4016f9892ff86c353;p=ard.is Simplify rng --- diff --git a/index.html b/index.html index 4157070..7121202 100644 --- a/index.html +++ b/index.html @@ -39,25 +39,19 @@ | |_| | | | |_| | | |__ | |_____|_| |_____|(_)_|___|`; - const rng1 = new Uint8Array(ascii.length); - const rng2 = new Uint8Array(ascii.length); - const rng3 = new Uint8Array(ascii.length); - const rng4 = new Uint8Array(ascii.length); - crypto.getRandomValues(rng1); - crypto.getRandomValues(rng2); - crypto.getRandomValues(rng3); - crypto.getRandomValues(rng4); + // 4 random numbers are required for each character + const rng = [...crypto.getRandomValues(new Uint8Array(ascii.length * 4))]; - for (const [index, finalChar] of [...ascii].entries()) { + for (const finalChar of ascii) { if (finalChar === '\n') { asciiContainer.insertAdjacentHTML('beforeend', '
'); continue; } - const startOffset = rng1[index]; // Initial delay before starting the cycle (implied max = 255ms) - const jump = rng2[index] % cycle.length; // How many cycle symbols to skip per tick - let cycleIndex = rng3[index] % cycle.length; // Which character to begin with in the cycle - let ticksRemaining = rng4[index] % maxTicks; // Number of ticks before settling + const startOffset = rng.pop(); // Initial delay before starting the cycle (implied max = 255ms) + const jump = rng.pop() % cycle.length; // How many cycle symbols to skip per tick + let cycleIndex = rng.pop() % cycle.length; // Which character to begin with in the cycle + let ticksRemaining = rng.pop() % maxTicks; // Number of ticks before settling const charElem = document.createElement('span'); asciiContainer.insertAdjacentElement('beforeend', charElem);