1. 常用的方法:
math.randomseed(os.time()) print(math.random())
2. 改进的方法:
math.randomseed(tostring(os.time()):reverse():sub(1, 6)) print(math.random())
3. 再改进的方法:
local socket = require("socket") -- 需要用到luasocket库 local function get_seed() local t = string.format("%f", socket.gettime()) local st = string.sub(t, string.find(t, "%.") + 1, -1) return tonumber(string.reverse(st)) end math.randomseed(get_seed()) print(math.random())
原文地址:http://blog.csdn.net/cjfeii/article/details/42736851