Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Math.Random has a Hidden While Loop Inside?

So my question is this, when you put in a math.random, there is a while loop built inside it right?

What I mean by this is it will keep on running the test again and again a pull out a random variable, at least that's what I understand. And if I'm correct is there any way for it to only run a test once? And is there any scenario where you would only need it to run once?

Hope you can help, and if you can't thank you for your time.

2 comments

0

It will only run once if you use it

0

No.

2 answers

Hi flippin,

How I understand math.random is that under each seed, there's a table of randomly generated values. So, when you call math.random() with a seed, it just returns a number from that table. Which is why, I recommend using math.randomseed(tick()) before you use math.random() because that will give you a completely random set of values to work with, since tick() changes according to time.

If you were to use just math.random() without changing the seed, it will just print the same values in the same sequence every time you run the game. So, if the first time it generated 2, 3, 4 on the first 3 runs, it will generate those same numbers again.

##Hope I helped and have a wonderful day/night.

####(P.S. I don't think math.random runs a loop every time you call it, that'd be inefficient on ROBLOX's side)

Thanks,

Best regards,

~~ KingLoneCat

FlippinAwesomeCrew,

Thank you for submitting this epic question. I thought about it for a very long time.

The answer is no

This discussion is preserved as it was. New answers, comments, and votes are closed.