shithub: orca

Download patch

ref: f865f1a64f13e4ef0edd5aa2b0f6d5621b22ba84
parent: 0c17ec914f67ddce353e79c972c9dd098a09281b
author: cancel <cancel@cancel.fm>
date: Sun Dec 2 11:00:15 EST 2018

Add better pseudorandom function

--- a/sim.c
+++ b/sim.c
@@ -667,6 +667,16 @@
   }
 END_PHASE
 
+static Usz hash32_shift_mult(Usz key) {
+  Usz c2 = UINT32_C(0x27d4eb2d);
+  key = (key ^ UINT32_C(61)) ^ (key >> UINT32_C(16));
+  key = key + (key << UINT32_C(3));
+  key = key ^ (key >> UINT32_C(4));
+  key = key * c2;
+  key = key ^ (key >> UINT32_C(15));
+  return key;
+}
+
 BEGIN_DUAL_PHASE_0(random)
   REALIZE_DUAL;
   BEGIN_DUAL_PORTS
@@ -691,7 +701,9 @@
     min = b;
     max = a;
   }
-  Usz val = (y * 5 + x * 3) * Tick_number % (max - min) + min;
+  Usz key = y * width + x;
+  key = hash32_shift_mult((y * width + x) ^ (Tick_number << UINT32_C(16)));
+  Usz val = key % (max - min) + min;
   POKE(1, 0, glyph_of(val));
 END_PHASE