Heim  >  Artikel  >  Web-Frontend  >  javascript Math.random()随机数函数_基础知识

javascript Math.random()随机数函数_基础知识

WBOY
WBOYOriginal
2016-05-16 18:42:251349Durchsuche

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之间)的公式

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn