Is there a way to set probablity between two things? Let say I want one photo to pop 80% of the times and another one to pop 20% of the times. Is there a shortcut to do so. I’ve written this code but it’ll be better if there’s a shorter way.
--# Main
--# Main
function setup()
photo = {}
photo[1] = readImage("Cargo Bot:Codea Icon")
photo[2] = readImage("Cargo Bot:Codea Logo")
t = 5
i = 1
previousi = 1
twop = 0
onep = 0
parameter.watch("percenttwo")
end
function draw()
background(255, 255, 255, 255)
t = t-1
if t==0 then
i = math.random(1,10)
if i==previousi then t=1 else
t = 5
previousi = i
end
end
if i<=8 then
p = 1
onep = onep+1
elseif i>8 then
p = 2
twop = twop+1
end
percenttwo = (twop/(twop+onep))*100
sprite(photo[p],WIDTH/2,HEIGHT/2)
end