Lua 随机数生成问题
lua 随机战斗游戏,每次每次创建玩家的时候属性基本都是一样的,因为使用了math.randomseed
(
os.time
());看完以下文章是math.randomseed()时间间隔太短造成的
Lua 生成随机数需要用到两个函数:
math.randomseed(xx), math.random([n [, m]])
1. math.randomseed(n) 接收一个整数 n 作为随机序列种子。
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函数
math.pi 为圆周率常量 = 3.14159265358979323846热门日志
分类
- Php(101)
- Java(8)
- Mysql(32)
- Ajax(2)
- Jsp(1)
- Struts(8)
- Linux(71)
- JavaScript(39)
- Staruml(0)
- Mouth(1)
- Html(6)
- Windows(8)
- Message(12)
- Lua(10)
- Compute(1)
- Redis(7)
- Nginx(11)
- Jquery(1)
- Apache(1)
- cocos2d-x(8)
- about(1)
- ssdb(1)
- Mac(7)
- C(1)
- memcache(1)
- Python(30)
- Vim(8)
- sed(2)
- ansible(3)
- awk(4)
- shell(3)
- Django(4)
- git(7)
- bat(4)
- svn(0)
- docker(1)
- Tornado(1)
- go(1)
- 架构(16)
- Vue(1)
最新日志
- Docker 那些事
- 欢迎您关注“刘善海价值分享”微信公众号!
- Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
- Linux vim/vi下backspace(退格键)出现^? 或^H
- python 如何通过subprocess.call调用自定义alias别名
- python2 python3中long类型的区别
- 10 个 Linux 中方便的 Bash 别名
- 'python' engine because the 'c' engine does not support regex separators
- importError c extension: No module named np_datetine not buit
- 四个提高工作效率的小技巧