'Calling a lua function at random time intervals in love2d

So basically I want to call a function in lua at random time intervals in love2d. Iam clueless of how to do this so any help is appreciated.



Solution 1:[1]

local t = math.random(MIN, MAX);

function love.update(dt)
    t = t - dt
    if t <= 0 then
       FUNCTION()
       t = math.random(MIN, MAX);
    end
end

Solution 2:[2]

try:

function love.load()
    Time = math.random(1, (max number here))
end

function love.update(dt)
    Time = Time - dt
    if Time < 0 then
       -- magic
       Time = math.random(1, (max number here))
    end
end

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 shingo
Solution 2