首页 > 语言 > JavaScript > 正文

javascript Math.random()随机数函数

2024-05-06 14:13:05
字体:
来源:转载
供稿:网友
random函数语法
Math.random();

random函数参数
无参数
random函数返回值
返回0和1之间的伪随机数,可能为0,但总是小于1,[0,1)

random函数示例
document.write(Math.random());

返回随机数
document.write(Math.random()*(20-10)+10);

返回10-20的随机数
document.write(Math.random()*(n-m)+m);

返回指定范围的随机数(m-n之间)的公式
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选