Author Topic: getRandom returning different results on mac and pc  (Read 2007 times)

That's exactly what I pointed out up there:

what

He is talking about utilizing setRandomSeed and then calling getRandom to return the same sequence of random numbers based on the seed, however, as I already explained, other scripts and even the engine itself are using the function as well, thus causing it to appear to "skip ahead" in the sequence (very basic explanation).

He is talking about utilizing setRandomSeed and then calling getRandom to return the same sequence of random numbers based on the seed, however, as I already explained, other scripts and even the engine itself are using the function as well, thus causing it to appear to "skip ahead" in the sequence (very basic explanation).
I realize that and Ipquarx pointed out what was wrong. zmaster was saying that the getRandom function didn't have an argument for a seed and that's what I pointed it. I had no idea there was a setRandomSeed.

What do you mean by different results?

btw:
double = getRandom(min,max);

On another note, it doesn't return a double-precision float. It always returns a string, syntaxically fixed to a integer or float with precision 6.

The problem here is that inside a function, there is say, the following code:
Code: [Select]
function blah()
{

setRandomSeed(1231410857510857584752610452674907490747475251113186867577116104117842712211751241120756767676774877366);

for(%a = 0; %a < 50; %a++)
{
echo(getRandom(0, 100));
}
}
Try that on mac and pc, it will return different results.
Why?
How can I fix that?
« Last Edit: May 19, 2012, 03:55:07 PM by Ipquarx »

You can't fix that.

You can't fix that.
Why do you say that? Is it because the seed is too big?

Why do you say that? Is it because the seed is too big?

Either that or the engine uses slightly different algorithms on Windows in comparison to Mac due to the precision of available libraries or other things.

In any case, don't use a seed with a precision higher than 6.

No, it definetly uses the same algorithm.
And you mean don't use numbers that have more than 5 decimal places, or are >= 1 million?

No, it definetly uses the same algorithm.
And you mean don't use numbers that have more than 5 decimal places, or are >= 1 million?

-999999 <= x >= 999999
-0.999999 <= x - floor(x) >= 0.999999

I think you mean
-999999 <= x <= 999999
-0.999999 <= x - floor(x) <= 0.999999


-999999 <= x <= 999999
-0.999999 <= x - floor(x) <= 0.999999
I assume that's what you meant as the acceptable range.

Allright, somewhat dissapointing, but there's still 999,998,000,001 possible seeds then, right? >.>

Sorry for the double post, but I tried what you said, and tried with decimal places, but doing this in the console:
setRandomSeed(68293.4945); echo(getRandomSeed());
outputs 68293, no decimal place.

Psh, reasons like this are why I always write my add-ons in C++ or Ruby or something then send/receive data to it instead of writing the data functions in Torque.

Psh, reasons like this are why I always write my add-ons in C++ or Ruby or something then send/receive data to it instead of writing the data functions in Torque.
Except that's slow and off topic.

Can someone please tell me why they return different results?