Jump to content

Convert Function To PHP


The Little Guy

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.