home ~ socials ~ projects ~ rss

Generate A Random Number Between To Integers In Lua

October 2024
function random_int(min, max) 
  math.randomseed(os.time())
  print(math.random(min, max))
end

print(random_int(1, 4))
Output:
4

The min and max are inclusive. So:

random_int(3, 9)

Can return values of:

3, 4, 5, 6, 7, 8, 9

end of line
Share link:
https://www.alanwsmith.com/en/2n/ag/90/dd/?generate-a-random-number-between-to-integers-in-lua