From 96e03f1aa88bbd0c7a4ee4a521ff2a4a7e853b88 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Wed, 23 Sep 2020 12:59:21 +0200 Subject: Update random post --- random.html | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/random.html b/random.html index 741f4e3..a24337d 100644 --- a/random.html +++ b/random.html @@ -28,16 +28,18 @@

Nathan further recommends the following hash function, which is not a cryptographic hash function but is nothing short of magical when applied for the right purpose: the Wang hash. + The version on Nathan's blog is somewhat outdated; there is an improved one to be found on the (also defunct) website of Thomas Wang himself (Internet Archive copy):

-
uint wang_hash(uint seed) {
-    // taken from Nathan Reed's blog post
-    seed = (seed ^ 61) ^ (seed >> 16);
-    seed *= 9;
-    seed = seed ^ (seed >> 4);
-    seed *= 0x27d4eb2d;
-    seed = seed ^ (seed >> 15);
-    return seed;
+
uint wang_hash(uint key) {
+    // Taken from Thomas Wang's website
+    key = ~key + (key << 15);   // key = (key << 15) - key - 1;
+    key = key ^ (key >>> 12);
+    key = key + (key << 2);
+    key = key ^ (key >>> 4);
+    key = key * 2057;   // key = key + (key << 3) + (key << 11);
+    key = key ^ (key >>> 16);
+    return key;
 }

-- cgit v1.2.3-70-g09d2