Math.Random making same output every time...
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Math.Random making same output every time...
Fortunately I only need math.random once.
Re: Math.Random making same output every time...
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.
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.
What have I gotten myself into?
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Math.Random making same output every time...
I've never heard of any PRNG API which doesn't keep internal state (outside of pure functional languages, like Clean and Haskell).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.
Help us help you: attach a .love.
Re: Math.Random making same output every time...
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.
What have I gotten myself into?
Who is online
Users browsing this forum: Google [Bot] and 2 guests