[HN Gopher] A Simple Hash for Perlin Noise
___________________________________________________________________
A Simple Hash for Perlin Noise
Author : thisismyswamp
Score : 22 points
Date : 2022-05-10 21:46 UTC (1 hours ago)
(HTM) web link (marcospereira.me)
(TXT) w3m dump (marcospereira.me)
| Dave_Rosenthal wrote:
| Ah, adventures in 'not quite as random as you thought' land.
|
| 1) I remember building a game in 90s where the locations of
| resources on a 2d game map were generated by successive calls to
| random() (and then were probably mod 1024ed or something). But,
| when we looked at the locations, they were clearly in a line
| pattern. Huh? After a while of confused debugging, we eventually
| discovered that the RNG was a linear congruential generator,
| which, when used the way we did to generate N-tuples, tends to
| produce points that tend to lie on a small number of N-1
| dimensional surfaces! Oops.
|
| 2) I remember a big debate with a statistician at a company we
| were selling data analytics software to. We were putting random
| data elements into random groups to support certain types of
| statistical analysis. He was adamant that the randomization we
| were doing would introduce bias into the data and showed us
| similar tests he had done that "proved it". He told us that his
| company would be dropping our product because they couldn't trust
| it. I told him that there was no way bias was introduced and I
| took a closer look at his tests. It turns out the RNG in whatever
| tool he was using was just not very good and it had apparently
| shaken his very understanding of statistics :) Luckily, I told
| him that we were using MD5 for randomness (once bitten!) and that
| if he simply redid his experiments with MD5 he would see the bias
| disappear. To say he was skeptical would be an understatement,
| but, thankfully for our contract, his tests didn't actually crack
| MD5, all bias was gone, and we got a very generous email from the
| skeptic informing us that he would be trusting our software for
| everything from now on.
| pcwalton wrote:
| FNV is slow because it only goes one byte at a time. An easy
| improvement for basically no extra complexity is the FxHash,
| which is popular in Rust for simple non-secure workloads:
| https://nnethercote.github.io/2021/12/08/a-brutally-effectiv...
|
| Obligatory disclaimer: Don't use any of this in cryptographic
| contexts.
| pubby wrote:
| I think I'm missing something. Why not call a PRNG for each array
| element? Seems like you could do this in 4 lines of code.
| foota wrote:
| "I couldn't rely on simple randomness since terrain generation
| has to be deterministic, especially for multiplayer games."
|
| You want the results to be repeatable. Now you could seed with
| something, but this has tradeoffs (e.g., you have to produce
| the same order of elements in order to get the same values out)
| eerikkivistik wrote:
| Maybe I am missing something, but wouldn't a regular random
| number generator with a defined seed work just as well? If the
| problem is determinism, then using a deterministic seed should
| give the same result.
| foota wrote:
| A desirable property for this is to be able to generate only
| some part of the terrain, but if you're using a seeded PRNG
| then you have to generate the same bits at a time. You could
| solve this with chunking, but it's not trivial.
| Sharlin wrote:
| If all you want to do is to generate a texture by looping over
| all pixels in sequence, then yes, you can use a RNG. But in
| many use cases you need to evaluate a noise function at an
| arbitrary (x, y) position (or (x, y, z) or even higher
| dimension) which means you need to hash the coordinates to get
| the pseudorandomness you want.
| pcwalton wrote:
| Correct, you can use an RNG. It's no coincidence that many RNGs
| and hashes (and, for that matter, ciphers) have similar
| constructions.
| ssklash wrote:
| This same hash is often used in Windows malware to avoid using
| the names of functions that are commonly used for malicious
| purposes, like `WriteProcessMemory`.
___________________________________________________________________
(page generated 2022-05-10 23:00 UTC)