lua Random Number
Moderators: Shine, Insert_witty_name
lua Random Number
is ther a way to create a random number in lua
thx mafia1ft
thx mafia1ft
You can use the function math.random([[start],end])
Without any specifications, it will return a number between 0 and 1, if you put in one number, it will return a number between 0 and that number, and if you put in two numbers, it will return a number between those.
A good idea would be to put math.randomseed(os.time()) at the beginning of your script, or else it will follow the same "random" sequence.
Without any specifications, it will return a number between 0 and 1, if you put in one number, it will return a number between 0 and that number, and if you put in two numbers, it will return a number between those.
A good idea would be to put math.randomseed(os.time()) at the beginning of your script, or else it will follow the same "random" sequence.
can someone please debug this code for me
thx
-- PSPRSP v0.1
-- MADE BY MAFIA1FT
DRAW = Image.load("PICS/DRAW.JPG")
WIN = Image.load("PICS/WIN.JPG")
LOSE = Image.load("PICS/LOSE.JPG")
sreen:clear()
pad = Controls.read()
-- X
if pad:cross() then
break
end
number = math.Random([[1], 3])
if number == 1 then
screen:blit(0,0,WIN)
end
if number == 2 then
screen:blit(0,0,LOSE)
end
if number == 3 then
screen:blit(0,0,DRAW)
end
screen.waitVblankStart()
screen.flip()
end
thx
-- PSPRSP v0.1
-- MADE BY MAFIA1FT
DRAW = Image.load("PICS/DRAW.JPG")
WIN = Image.load("PICS/WIN.JPG")
LOSE = Image.load("PICS/LOSE.JPG")
sreen:clear()
pad = Controls.read()
-- X
if pad:cross() then
break
end
number = math.Random([[1], 3])
if number == 1 then
screen:blit(0,0,WIN)
end
if number == 2 then
screen:blit(0,0,LOSE)
end
if number == 3 then
screen:blit(0,0,DRAW)
end
screen.waitVblankStart()
screen.flip()
end
Et voila!
DRAW = Image.load("PICS/DRAW.JPG")
WIN = Image.load("PICS/WIN.JPG")
LOSE = Image.load("PICS/LOSE.JPG")
while true do
screen:clear()
pad = Controls.read()
-- X
if pad:cross() then
break
end
number = math.Random(1,3)
if number == 1 then
screen:blit(0,0,WIN)
end
if number == 2 then
screen:blit(0,0,LOSE)
end
if number == 3 then
screen:blit(0,0,DRAW)
end
screen.waitVblankStart()
screen.flip()
end
DRAW = Image.load("PICS/DRAW.JPG")
WIN = Image.load("PICS/WIN.JPG")
LOSE = Image.load("PICS/LOSE.JPG")
while true do
screen:clear()
pad = Controls.read()
-- X
if pad:cross() then
break
end
number = math.Random(1,3)
if number == 1 then
screen:blit(0,0,WIN)
end
if number == 2 then
screen:blit(0,0,LOSE)
end
if number == 3 then
screen:blit(0,0,DRAW)
end
screen.waitVblankStart()
screen.flip()
end
Last edited by Ats on Wed Mar 29, 2006 7:47 pm, edited 1 time in total.
use the math random like this:
Code: Select all
math.floor(math.random(1,3))--if the number is a decimal it will take the integer from it (basicly)
math.ceil(math.random(1,3))--if the number is a decimal it will add one to the integer n leave off the decimal part(basicly)
DRAW = Image.load("PICS/DRAW.JPG")
WIN = Image.load("PICS/WIN.JPG")
LOSE = Image.load("PICS/LOSE.JPG")
while true do
screen:clear()
pad = Controls.read()
-- X
if pad:cross() then
break
end
number = math.random(3)
if number == 1 then
screen:blit(0,0,WIN)
end
if number == 2 then
screen:blit(0,0,LOSE)
end
if number == 3 then
screen:blit(0,0,DRAW)
end
screen.waitVblankStart()
screen.flip()
end
WIN = Image.load("PICS/WIN.JPG")
LOSE = Image.load("PICS/LOSE.JPG")
while true do
screen:clear()
pad = Controls.read()
-- X
if pad:cross() then
break
end
number = math.random(3)
if number == 1 then
screen:blit(0,0,WIN)
end
if number == 2 then
screen:blit(0,0,LOSE)
end
if number == 3 then
screen:blit(0,0,DRAW)
end
screen.waitVblankStart()
screen.flip()
end