时间相关
系统时间
--时间相关
-- 获取系统时间(时间戳)
print(os.time())
获得一个时间戳
-- 跟上那个相反,把我们现在的时间弄成时间戳
print(os.time({year = 2021,month = 7 ,day =21}))
*os.date('t’)
--os.date('*t')
local time = os.date('*t')
for k,v in pairs(time) do
print(k,v)
end
print(time.hour)
数学运算
--数学运算相关
--math
--绝对值
print(math.abs(-11))
--弧度转角度
print(math.deg(math.pi)) --pi是3.14的意思
--三角函数传弧度
print(math.cos(math.pi))
--最大最小值
print(math.max(1,2))
print(math.min(1,2))
--整数小数分离
print(math.modf(1.2))
--幂运算
print(math.pow(2,2)) --这个功能跟^类似
--开方
print(math.sqrt(4))
--随机数
--先设置随机数种子
--随机数种子要不断变化,否则你一直刷出来的都是一个值,因为os.time()(系统时间)每秒是不断变化的,所以传这个进来
math.randomseed(os.time())--lua中的os.time()是基于秒的,不太满足lua对随机数种子的要求(如果设置随机数种子的频率太高的话)
print(math.random(100))--第一个参数不变
print(math.random(100))
--第二种随机数生成方法
math.randomseed(tostring(os.time()):reverse():sub(1, 9))
print(math.random(100))
为什么使用LUA的时候,第一个随机数总是固定
http://www.cppblog.com/maosher/archive/2009/05/13/82772.html