How would the following pseudocode translate into Python?
function IntNoise(32-bit integer: x)
x = (x<<13) ^ x;
return ( 1.0 - ( (x * (x * x * 15731 + 789221) + 1376312589) & 7fffffff) / 1073741824.0);
end IntNoise function
I’m not sure about the following items: the 32-bit integer: x argument in the IntNoise call ; the <<, and the &7fffffff.
The function is a random number generator from this webpage: Perlin Noise.
Line by line, here are the changes:
function IntNoise(32-bit integer: x)We don’t need to declare the argument type, and prefer not to use CamelCase, so line one is:
The only thing wrong with the next line is the semicolon. Removing it, we get:
x will be shifted to the left by 13 bits and then the result will be bitwise exclusive-OR-ed with the starting value of x.
On the next line, once again no semicolon, and the
7ffffffneeds to be prefixed with0x, thus:Altogether, this makes: