您的位置:首页 > 编程语言 > Lua

Lua笔记:生成随机数

2015-04-17 15:50 155 查看
--------------------------- 生成随机数 -----------------------------------------
--1. 第一种方法
math.randomseed(os.time()) --设置随机数种子
--2. 第二种方法
math.randomseed( tonumber(tostring(os.time()):reverse():sub(1,6)))

--生成随机数
--返回 0 和 1 之间的随机数
local randomNum = math.random()
--返回 1 和 10 之间的随机数
local randomNum = math.random(10)
--返回 minRandom 和 maxRandom 之间的随机数
local randomNum = math.random(minRandom, maxRandom)
--------------------------- 生成随机数 -----------------------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: