Stevor 0 Posted March 13 Share Posted March 13 hello i have script with use math.random ( First Number , second Number ) but some times the number same old number ( spam ) what can do Link to post

Tekken 146 Posted March 13 Share Posted March 13 You mean it outputs two times the same number in a row? If so you can store the old number in a variable and check if is the same or not and store the number in var again. Something like this: local lastnr = math.random(0, 9); function generatenr() local newnr = math.random(0, 9); if newnr ~= lastnr then print(newnr); lastnr = newnr; --overwrite old nr else generatenr();--recall function if the same nr end end Link to post

Stevor 0 Posted March 14 Author Share Posted March 14 13 hours ago, Tekken said: You mean it outputs two times the same number in a row? If so you can store the old number in a variable and check if is the same or not and store the number in var again. Something like this: local lastnr = math.random(0, 9); function generatenr() local newnr = math.random(0, 9); if newnr ~= lastnr then print(newnr); lastnr = newnr; --overwrite old nr else generatenr();--recall function if the same nr end end when i use lastnr to orginal random outputChatBox(lastnr,0,0,0,true) --after start or restart its same number export --and --when i use newnr outputChatBox(newnr,0,0,0,true) --debug bad argument Link to post

Tekken 146 Posted March 14 Share Posted March 14 at the top of your script add this math.randomseed(getTickCount()); This will make it so the resource won't output the same random numbers every time it's restarted! Link to post

Stevor 0 Posted March 14 Author Share Posted March 14 27 minutes ago, Tekken said: at the top of your script add this math.randomseed(getTickCount()); This will make it so the resource won't output the same random numbers every time it's restarted! but what to use ? newnr or lastnr Link to post

Tekken 146 Posted March 14 Share Posted March 14 You use newnr if it's not the same as the lastnr if it is the same you just redo math.random to have a different one Link to post

Stevor 0 Posted March 14 Author Share Posted March 14 4 minutes ago, Tekken said: You use newnr if it's not the same as the lastnr if it is the same you just redo math.random to have a different one same thing bad argument when i use it i need to use 1 math.random only i can't use 2 Link to post

SpecT 55 Posted March 14 Share Posted March 14 This should work for you: local lastNumber function getRandomNumber(from, to) local randNumber = math.random(from, to) -- generate random numbers until randNumber is different than lastNumber while(randNumber == lastNumber) do randNumber = math.random(from, to) end lastNumber = randNumber return randNumber end function testerino() outputChatBox(getRandomNumber(1,5)) end addCommandHandler("ok",testerino) Link to post

Stevor 0 Posted March 14 Author Share Posted March 14 2 hours ago, SpecT said: This should work for you: local lastNumber function getRandomNumber(from, to) local randNumber = math.random(from, to) -- generate random numbers until randNumber is different than lastNumber while(randNumber == lastNumber) do randNumber = math.random(from, to) end lastNumber = randNumber return randNumber end function testerino() outputChatBox(getRandomNumber(1,5)) end addCommandHandler("ok",testerino) thx it's work good Link to post

## 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 account## Sign in

Already have an account? Sign in here.

Sign In Now