undefined Posted June 6, 2018 Share Posted June 6, 2018 (edited) random_number = function(first, second) if first < 0 and second < 0 then return -math.random(math.abs(first), math.abs(second)) elseif first > 0 and second < 0 then if math.random(2) == 1 then return math.random(0, first) else return -math.random(0, math.abs(second)) end elseif first < 0 and second > 0 then if math.random(2) == 1 then return -math.random(0, math.abs(first)) else return math.random(0, second) end else return math.random(first, second) end end Solved. Edited June 6, 2018 by ZoRRoM Link to comment
Discord Moderators Pirulax Posted June 8, 2018 Discord Moderators Share Posted June 8, 2018 I cant undestand this junk code, sorry. Why do you have this much statemenets? Why not just redefine the values of the variables, and at the end just return it with math.random? And if you need true randomness: function totallyRandomRandom(first, second) math.randomseed(math.random(0, getTickCount())+getTickCount()) return math.random(first, second) end Link to comment
ShayF2 Posted June 8, 2018 Share Posted June 8, 2018 local last function getRandom(first, second) if second > first then local rand = math.random(first, second) if rand == last then return getRandom(first, second) end last = rand return rand end return false end This will get a random number between first and second, making sure its not the same as the last random number you got as well as making sure that its a valid math operation. I hope this helps. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now