The Little Guy Posted March 20, 2012 Share Posted March 20, 2012 Anyone know how to convert this to php? 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 tried, and passing numbers to it isn't working, I am always getting 1 for a result, I should be getting anything between -1 and 1 My attempt: function random($x){ $x = pow($x<<13, $x); return ( 1.0 - ( ($x * ($x * $x * 15731 + 789221) + 1376312589) & 0xFFFFFF) / 1073741824.0); } Link to comment https://forums.phpfreaks.com/topic/259369-convert-function-to-php/ Share on other sites More sharing options...
kicken Posted March 20, 2012 Share Posted March 20, 2012 I'm not sure what the source language is, but I'd guess that the ^ in (x<,13)^x does not mean 'to the power of', instead it probably means xor. The symbol for that in PHP is the same thing, ^ $x = ($x<<13) ^ $x; return ( 1.0 - ( ($x * ($x * $x * 15731 + 789221) + 1376312589) & 0xFFFFFF) / 1073741824.0); Link to comment https://forums.phpfreaks.com/topic/259369-convert-function-to-php/#findComment-1329632 Share on other sites More sharing options...
chrsm Posted March 20, 2012 Share Posted March 20, 2012 He's also missing something: 0x7FFFFFFF, not FFFFFFFF. function random($x){ $x = ($x << 13) ^ $x; return ( 1.0 - ( ($x * ($x * $x * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0); } echo random(3); Link to comment https://forums.phpfreaks.com/topic/259369-convert-function-to-php/#findComment-1329635 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.