From b894698e94573e0c146ccbc4016f9892ff86c353 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Mon, 5 Jun 2023 00:22:46 -0700 Subject: [PATCH] Simplify rng --- index.html | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) 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); -- 2.47.3