Lua Math函数

函数名 描述 示例 结果

pi	圆周率	math.pi	                3.1415926535898
abs	取绝对值	math.abs(-2012)	        2012
ceil	向上取整	math.ceil(9.1)	    10
floor	向下取整	math.floor(9.9)	    9
max	取参数最大值	math.max(2,4,6,8)	8
min	取参数最小值	math.min(2,4,6,8)	2
pow	计算x的y次幂	math.pow(2,16)	    65536
sqrt	开平方	math.sqrt(65536)	256
mod	      取模	math.mod(65535,2)	1
modf取整数和小数部分math.modf(20.12) 20   0.12

-- 在使用math.random函数之前必须使用此函数设置随机数种子
randomseed   设随机数种子 math.randomseed(os.time())	  
random	        取随机数	 math.random(5,90)	   5~90
-- 游戏示例
function Game:Init()
	-- 初始化随机座位号(暂时这样写,遗留问题:断线重连座位号可能会变,不能随机)
	math.randomseed(tostring(os.time()):reverse():sub(1, 6))
	local minId, maxId
	for k, v in pairs(define.ViewId) do
		if nil == minId or k < minId then
			minId = k
		end
		if nil == maxId or k > maxId then
			maxId = k
		end
	end
	self.bankerViewID = nil -- 庄家座位号
	self.nMyViewId = math.random(minId, maxId)	
end


rad	角度转弧度	math.rad(180)	    3.14159265
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值