Rounding random numbers to the nearest hundredth?
Posted: Tue Sep 02, 2008 1:25 am
How can I round random numbers to the nearest hundredth?
Also, I'm making a "stock market" demo and I want the stocks to randomize + at most $5 or - at most $5 every 3 seconds.
so I would have
stock1 = 50 3 seconds stock1 = 53.45
or something.
Please help me with changes I need to make the above possible.
My current code
(Yes I know my math.random thing is not correct I just put it in there to test.)
Also, I'm making a "stock market" demo and I want the stocks to randomize + at most $5 or - at most $5 every 3 seconds.
so I would have
stock1 = 50 3 seconds stock1 = 53.45
or something.
Please help me with changes I need to make the above possible.
My current code
(Yes I know my math.random thing is not correct I just put it in there to test.)
Code: Select all
function load()
love.graphics.setFont(love.graphics.newFont(love.default_font, 12))
stock1 = 50
stock2 = 50
stock3 = 50
end
function update(dt)
stock1 = stock1 + (dt * (math.random (-100,100))) - (dt * (math.random (-100,100)))
stock2 = stock2 + (dt * (math.random (-100,100))) - (dt * (math.random (-100,100)))
stock3 = stock3 + (dt * (math.random (-100,100))) - (dt * (math.random (-100,100)))
end
function draw()
love.graphics.draw(stock1, 50, 50)
love.graphics.draw(stock2, 50, 100)
love.graphics.draw(stock3, 50, 150)
end