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

I realized that, so i said AVOID.

You cannot fix, prevent or avoid (or whatever fancy word you can find) this problem. Although, you could read the post I quoted many times in replies to your posts which contained information on another way you could achieve similar functionality without this problem.

Okay.

The reason I don't want to use TCP objects is because it's a function, and it needs to return the output from the function directly, not from a separate object. That wouldn't work for my purposes.

But I will take the advice of making my own generator.

But I will take the advice of making my own generator.

I really don't see the purpose of needing non-random numbers from a PRNG. I mean, I get that sometimes you want to be able to re-generate the same values but that should still work on Windows and Mac, just with different values for both.

I really don't see the purpose of needing non-random numbers from a PRNG. I mean, I get that sometimes you want to be able to re-generate the same values but that should still work on Windows and Mac, just with different values for both.

For one example of how non-random values can be useful, research Minecraft's world generation.

For one example of how non-random values can be useful, research Minecraft's world generation.
Well, I mean, yeah. That's why I said "I get that sometimes you want to be able to re-generate the same values" but I doubt that this guy needs seeded terrain generation that you can duplicate on Windows and Mac using the same seed.

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?

Try doing setRandomSeed inside of the for loop (ie. directly before each getRandom call). If that doesn't work, use a linear-congruential generator, it's the fastest RNG (especially in Torque) and it works fine for everything but cryptography. I've used it for terrain generation before.

EDIT: To clarify, yes I completely understand how seeds work, but there is a (tiny) chance that setRandomSeed in fact sets what previous seeded values to use, and doesn't actually re-seed the RNG. It could be that the seed is being changed in the background before the getRandom call. Again unlikely, just making hopeful guesses so you don't have to result to your own TorqueScript (yuck) implementation of an RNG.
« Last Edit: May 26, 2012, 04:31:52 AM by Destiny/Zack0Wack0 »