C#.NET:
public int NextRandom(int n) {
int n2 = (n + 7) * 3;
n = ((int)((uint)n >> 8) | n << 24);
n ^= ((int)((uint)n >> 7) & 0x3FF) * ((int)((uint)n >> 22) & 0x3FF) + 5 * (n2 + 3);
return n;
}
NextRandom(1337);
C# RETURN: 956321482
PHP:
public function NextRandom($n) {
$n2 = ($n + 7) * 3;
$n = ((int)(abs($n) >> 8) | $n << 24);
$n ^= ((int)(abs($n) >> 7) & 0x3FF) * ((int)(abs($n) >> 22) &
0x3FF) + 5 * ($n2 + 3);
return $n;
}
NextRandom(1337);
PHP RETURN: 22431157962
What is wrong in my PHP code? Tanks for help.
SOLVED: I add
$n &= 0xFFFFFFFF;
to put the integer back into 32-bit range.
(uint)casting in one andabs()in the other, or one of your constants are different.