diff options
author | Tom Smeding <tom.smeding@gmail.com> | 2020-09-23 12:59:21 +0200 |
---|---|---|
committer | Tom Smeding <tom.smeding@gmail.com> | 2020-09-23 12:59:21 +0200 |
commit | 96e03f1aa88bbd0c7a4ee4a521ff2a4a7e853b88 (patch) | |
tree | 471e6850fea5454734ddb96bb9deeedef4f47c0a | |
parent | 20fdc927770e478685ddb502296259df46513a69 (diff) |
Update random post
-rw-r--r-- | random.html | 18 |
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 >> 16); - seed *= 9; - seed = seed ^ (seed >> 4); - seed *= 0x27d4eb2d; - seed = seed ^ (seed >> 15); - return seed; +<pre>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; }</pre> <p> |