]> git.ardis.lu - ard.is/commitdiff
Simplify rng
authorArdis Lu <ardisglu@gmail.com>
Mon, 5 Jun 2023 07:22:46 +0000 (00:22 -0700)
committerArdis Lu <ardisglu@gmail.com>
Mon, 5 Jun 2023 07:22:46 +0000 (00:22 -0700)
index.html

index 4157070eaa35fddb02ea253bf73ebe285305056d..712120203ae87809da58963f2b135c26a54ea4ac 100644 (file)
 | |_| | | | |_| |  | |__ |
 |_____|_| |_____|(_)_|___|`;
 
-    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', '<br>');
         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);
This page took 0.034687 seconds and 4 git commands to generate.