summaryrefslogtreecommitdiff
path: root/random.html
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-09-23 12:59:21 +0200
committerTom Smeding <tom.smeding@gmail.com>2020-09-23 12:59:21 +0200
commit96e03f1aa88bbd0c7a4ee4a521ff2a4a7e853b88 (patch)
tree471e6850fea5454734ddb96bb9deeedef4f47c0a /random.html
parent20fdc927770e478685ddb502296259df46513a69 (diff)
Update random post
Diffstat (limited to 'random.html')
-rw-r--r--random.html18
1 files 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 @@
<p>
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 (<a href="https://web.archive.org/web/20111127152414/http://www.cris.com/~ttwang/tech/inthash.htm" target="_blank">Internet Archive copy</a>):
</p>
-<pre>uint wang_hash(uint seed) {
- // taken from Nathan Reed's blog post
- seed = (seed ^ 61) ^ (seed &gt;&gt; 16);
- seed *= 9;
- seed = seed ^ (seed &gt;&gt; 4);
- seed *= 0x27d4eb2d;
- seed = seed ^ (seed &gt;&gt; 15);
- return seed;
+<pre>uint wang_hash(uint key) {
+ // Taken from Thomas Wang's website
+ key = ~key + (key &lt;&lt; 15); // key = (key &lt;&lt; 15) - key - 1;
+ key = key ^ (key &gt;&gt;&gt; 12);
+ key = key + (key &lt;&lt; 2);
+ key = key ^ (key &gt;&gt;&gt; 4);
+ key = key * 2057; // key = key + (key &lt;&lt; 3) + (key &lt;&lt; 11);
+ key = key ^ (key &gt;&gt;&gt; 16);
+ return key;
}</pre>
<p>