shithub: orca

Download patch

ref: b87bcd287c6a5eae12cc57ffe556ec52871491b6
parent: 5d6b4dbaf02e23ef1ba18ab90db8d5927d427505
author: cancel <cancel@cancel.fm>
date: Thu Jan 2 11:48:41 EST 2020

Cleanup

--- a/sim.c
+++ b/sim.c
@@ -611,16 +611,6 @@
   }
 END_OPERATOR
 
-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_OPERATOR(random)
   LOWERCASE_REQUIRES_BANG;
   PORT(0, -1, IN | PARAM);
@@ -641,8 +631,16 @@
     min = b;
     max = a;
   }
-  Usz key = hash32_shift_mult((extra_params->random_seed + y * width + x) ^
-                              (Tick_number << UINT32_C(16)));
+  // Initial input params for the hash
+  Usz key = (extra_params->random_seed + y * width + x) ^
+            (Tick_number << UINT32_C(16));
+  // 32-bit shift_mult hash to evenly distribute bits
+  key = (key ^ UINT32_C(61)) ^ (key >> UINT32_C(16));
+  key = key + (key << UINT32_C(3));
+  key = key ^ (key >> UINT32_C(4));
+  key = key * UINT32_C(0x27d4eb2d);
+  key = key ^ (key >> UINT32_C(15));
+  // Hash finished. Restrict to desired range of numbers.
   Usz val = key % (max - min) + min;
   POKE(1, 0, glyph_of(val));
 END_OPERATOR