随机数(Lua编写)

Math.seed = 5
 Math.seededRandom = function(max, min) 
   max = max or 1
   min = min or 0

   Math.seed = (Math.seed * 9301 + 49297) % 233280
   local rnd = Math.seed / 233280.0

   return min + rnd * (max - min)
 end

 for  i = 1, 2 do
     print(Math.seededRandom())
 end

 local max1 = 0
 local seed1 = 0

 while 1 do
   seed1 = Math.seededRandom()
   if max1 < seed1 then
     max1 = seed1
     print(max1)
   end
 end
View Code

 

posted @ 2017-03-02 14:47  【Winco】  阅读(1613)  评论(0编辑  收藏  举报