This Code isn't creating random numbers/outputs
local b1 = mob.B1 math.randomseed(tick()) p1 = math.random(1, 100) if p1 <= b1.None.Value then elseif p1 > b1.None.Value and p1 <= b1.Crude.Value then print("Crude for b1") elseif p1 > b1.Crude.Value and p1 <= b1.Rare.Value then print("Rare for b1") elseif p1 > b1.Rare.Value and p1 <= b1.Famed.Value then print("Famed for b1") elseif p1 > b1.Famed.Value and p1 <= b1.Legendary.Value then print("Legendary for b1!")
Here is my solution:
math.randomseed(os.time()) -- NOTE I USED OS.TIME, NOT TICK! math.random(); math.random();
I think this is related to a question from a few days ago: Random always picks last element in table?
My answer there was:
Yikes! You've stumbled on a whopper. Have a look at this question on StackOverflow.
Basically, the ROBLOX version of Lua relies on a cross-platform C implementation of rand(3)
, which, if you're on OSX [or Windows 10], isn't the best generator.
I tested this on OSX and, you're right, the first generated number is the same regardless of the seed! To mitigate this, call math.random() a couple of times before you actually use the output - the rest of the numbers are random, just not the first one.