6
$\begingroup$

How/why does this noise function work?

function noise(x)     x = (x << 13) ^ x;     return (1.0 - ((x * (x * x * 15731 + 789221) + 1376312589) & 0x7fffffff)                / 1073741824.0); 

I've found it in several places with different primes, but couldn't find an actual explanation of why/how it works.

I know what the code itself is doing (shift, xor, multiply-and-overflow, bitwise-and w/ intmax - 1, etc), but I don't get why those things are done or how it results in acceptable noise.

Why are these operations, why this order? Why primes? I know "because non-primes can generate observable patterns", but why is that?

Why divide by (2**32 - 1)/2? or rather, why does that give a 0..2 value?

  • 4
    What is a noise function, and what does it mean for a noise function to work?2011-06-15
  • 0
    Looks like some kind of a PRNG to me. I'm not sure that there is much theory behind this. I added a *random* tag to attract people who might be more knowledgeable. That 0x7ff... is $2^{31}-1$ and the divisor is $2^{30}$. Therefore the result is 1.0-something, with something in the interval $[0,2)$. So (barring a mistake) the values $\in(-1,1]$.2011-06-15
  • 0
    I suppose the word 'noise' is used here in the sense of 'white-noise' process. It seems some kind of pseudo-random number generator2011-06-15
  • 0
    `I've found it in several places` Where?2011-06-15
  • 0
    @leonbloy here's one page: http://freespace.virgin.net/hugo.elias/models/m_perlin.htm2014-10-27

2 Answers 2