Author Topic: Random generator not compatible with torque?  (Read 1714 times)

I found an RNG online and tried to implement it in blockland like so:

function pn_get(%x, %y) {
  %n = %x + %y * 57;
  %n = mPow(%n << 13, %n);
  return 1.0 - ((%n * (%n * %n * 15731 + 789221) + 1376312589) & 2147483647) / 1073741824;    
}


It always returns -0.282541.
If %y is negative it returns -0.281791.
(2147483647 was previously 7fffffff but blockland hates hex in expressions and would return a syntax error.)
Any idea why it does this?
« Last Edit: June 20, 2012, 10:34:54 AM by ThinkInvisible »

Is there an issue with getRandom() that doesn't fit your needs?

Is there an issue with getRandom() that doesn't fit your needs?
Yes, this runs off of a seed while getRandom() can't be controlled at all.

i thought getRandom() did use a seed, you just had to set it yourself with a function before?
although i think it's the same seed all other calls to the function will use too

function pn_get(%x, %y) {
  %n = %x + %y * 57;
  %n = mPow(%n << 13, %n);
  return 1.0 - ((%n * (%n * %n * 15731 + 789221) + 1376312589) & 2147483647) / 1073741824;    
}
I added echos and ran the function and ended up with this.


The result from the bolded part is far too big of a number to be used.
« Last Edit: June 20, 2012, 11:47:54 AM by Daenth »

So how would I reduce that without completely ruining the whole thing?

So how would I reduce that without completely ruining the whole thing?
Lol, Torque.

getRandom() can't be controlled at all.
What

What


yes
yes it can

setRandomSeed(%Seed);
getRandomSeed();


And also it's failing because the numbers you're using are too big for torque.

-snip-

...Well, I didn't know THAT.
But still, I should probably have some other variations.

Seems oddly uniform. Keeps returning something like .9 .8 .7 .6 .5 .4 .3 .2 .1 .0 .9 .8 etc. if both X and Y increment steadily.
« Last Edit: June 20, 2012, 01:59:56 PM by ThinkInvisible »

RNG is now working but it's generating one-dimensional noise while the rest of the script handles two-dimensional.
If I simply add %x and %y together it makes this weird checkerboard pattern.
What do?

That's not a coding problem then, that's most likely the algorithm you're using.

Try getting a better one.