Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Math.Random has a Hidden While Loop Inside?

Asked by 5 years ago

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.

0
It will only run once if you use it Simnico99 206 — 5y
0
No. User#6546 35 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago

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

Ad
Log in to vote
0
Answered by 5 years ago

FlippinAwesomeCrew,

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

The answer is no

Answer this question