Jump to content

random spam


Recommended Posts

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
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

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
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
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

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
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

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...