How/why does this noise function work? 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?
 A: The function spreads the information contained in the input value across the full 32 bits, then scales it down to the range $-1..1$.
This first part makes the input affect both lower and higher bits:
x = (x << 13) ^ x;

Then that information is spread across the available domain (32 bits) by multiplying and adding it to three constants of different magnitudes - one small, one medium and one large:
digest = x * (x * x * 15731 + 789221) + 1376312589

Finally, the "random" integer is scaled down. 0x7fffffff is $2^{31}$, so the bitwise AND operation makes sure the number is in the range $0..2^{31}$. 1073741824 is $2^{30}$, and $2^{31} \div 2^{30} = 2$, so after the division the range will be $0..2$. Subtracting from $1$ shifts the range to be $-1..1$.
return 1.0 - ((digest & 0x7fffffff) / 1073741824.0);

I'm not sure why the constants need to be prime. Perhaps primes have better bit patterns for this kind of thing.
It's worth noting that the result of this function will be different in different programming languages. It's very likely that there will be an integer overflow, which is language-dependent even for unsigned 32-bit integers. In Python3 the number may be promoted to have more than 32 bits, so it will give some result even though there will be no overflow (but overflow might be desirable to increase randomness). In JavaScript the function fails completely for large numbers, because the bitwise AND always results in 0 for very large numbers (in my tests).
A: It is a random noise generator. Did Google search on:
"noise function" 0x7fffffff
See:
http://www.qwerty-games.com/viewvc/Sardon3D/Branches/Networking/src/Noise.cpp?view=markup
http://libnoise.sourceforge.net/noisegen/index.html
