Page 2 of 2

Re: Math.Random making same output every time...

Posted: Mon Jul 16, 2012 2:57 pm
by Bannana97
Fortunately I only need math.random once.

Re: Math.Random making same output every time...

Posted: Mon Jul 16, 2012 4:01 pm
by AaronV
Oh so it adds the number for you. Well never mind then! ;)

Assumed it was like the ones where YOU have to tell it what the seed it.
Should've known better. This is a scripting language, not the other kind. Of course it works the way a sane person would have it work.



More TERRIBLE advice:
I would generate one random number for each option, add them together, and get the modulus.
If you need it to be EXACTLY FAIR.
Zero usually has half odds or no odds, and some of the higher numbers are 999 vs 1000 chances due to the whole bits thing.
Say you want to roll an imaginary dice out of a random number from 0-255 using mod 6.
Problems are you can't actually generate a zero (in the case of LFSRs and others).
And 255 isn't divisible by 6.
odds:
[1]...(mod = 1)...43 chances
[2]...(mod = 2)...43 chances
[3]...(mod = 3)...43 chances
[4]...(mod = 4)...42 chances
[5]...(mod = 5)...42 chances
[6]...(mod = 0)...42 chances

That's not a huge problem but the margin of error is based on how many choices you have.
Some outcomes can have up to 50% less odds than others with enough choices.


Lua probably pulls out a random number from 1 to 2^32 though, so unless you have over 2^31 choices, I wouldn't sweat it.

Re: Math.Random making same output every time...

Posted: Mon Jul 16, 2012 5:44 pm
by Robin
AaronV wrote:Assumed it was like the ones where YOU have to tell it what the seed it.
Should've known better. This is a scripting language, not the other kind. Of course it works the way a sane person would have it work.
I've never heard of any PRNG API which doesn't keep internal state (outside of pure functional languages, like Clean and Haskell).

Re: Math.Random making same output every time...

Posted: Mon Jul 16, 2012 7:47 pm
by AaronV
Meh, you're probably right. I build my own sometimes so I've studied a couple of non standard ones. Guess I got some crazy idea in my head. Forget I brought it up.