lua -- 数学库

1. 伪随机数生成函数

* math.random

1) math.random() 返回一个在区间[0, 1)内均匀分布的伪随机实数。

> = math.random()
0.39438292681909
> = math.random()
0.78309922375861

2)math.random(n) n为实数,返回一个在区间[1, n]内的伪随机整数。

> = math.random(6)
5
> = math.random(6)
6
> = math.random(6)
2

> = math.random(6.28)
2
> = math.random(6.28)
4
> = math.random(6.28)
6

3) math.random(m, n) m,n均为整数,n >= m,返回一个在区间[m,n]内的伪随机整数。 

> = math.random(3,10)
7
> =  math.random(3,10)
5
> = math.random(3,10)
8
> = math.random(10,10)
10
> = math.random(10,10)
10
> = math.random(10,3)
stdin:1: bad argument #2 to 'random' (interval is empty)
stack traceback:
    [C]: in function 'random'
    stdin:1: in main chunk
    [C]: in ?

 2. math.huge

huge为Lua可以表示的最大数字,huge可能是一个特殊值: inf。表示+infinity。

> = math.huge
inf

 参考:http://lua-users.org/wiki/MathLibraryTutorial

 

转载于:https://www.cnblogs.com/tingliang/archive/2013/06/09/3130132.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值