Lua 随机数生成问题

2014-3-14 杜世伟 Lua

lua 随机战斗游戏,每次每次创建玩家的时候属性基本都是一样的,因为使用了math.randomseed(os.time());看完以下文章是math.randomseed()时间间隔太短造成的

Lua 生成随机数需要用到两个函数:
math.randomseed(xx), math.random([n [, m]])

1. math.randomseed(n) 接收一个整数 n 作为随机序列种子。

阅读全文>>

标签: lua math random

评论(0) 浏览(4120)

lua 随机战斗游戏

2014-3-12 杜世伟 Lua

----初始化玩家数据
function create_player()
for num=1,2,1 do  -- 创建两个玩家
local tmp = {name="newplayer",hp=0,mp=0,atk=0,def=0,spd=0,luk=0,mg=0}
randomseed();
tmp.hp  = math.random(400,1000);
tmp.mp  = math.random(1,100);
tmp.atk = math.random(1,100);
tmp.atk = math.random(1,100);
tmp.spd = math.random(1,100);
tmp.luk = math.random(1,100);
tmp.mg = math.random(1,100);
table.insert(players,tmp);
end
end

阅读全文>>

标签: lua math random

评论(0) 浏览(4161)

Powered by emlog 沪ICP备2023034538号-1