Math.Random making same output every time...

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Bannana97
Citizen
Posts: 77
Joined: Wed May 16, 2012 2:49 pm

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

Post by Bannana97 »

Fortunately I only need math.random once.
AaronV
Prole
Posts: 16
Joined: Sun Jul 08, 2012 4:11 am

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

Post 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.
What have I gotten myself into?
User avatar
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...

Post 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).
Help us help you: attach a .love.
AaronV
Prole
Posts: 16
Joined: Sun Jul 08, 2012 4:11 am

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

Post 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.
What have I gotten myself into?
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests