[JavaScript-數學類]取隨機數的函數-使用Math.random()


說明:
Math.random()取出取隨機數
隨機數取得0~1之間的小數,
例:
取出1~100正數值,取出10個數。

程式:
<script type="text/javascript">
   document.write("取隨機數為:"+Math.random()+"<br>");
for(i=1;i<=10;i++){
document.write("第"+i+"個取隨機數為:"+Math.floor(Math.random()*100)+"<br>");
}
</script>
結果:



圖:










 














其它文章


arrow
arrow
    創作者介紹
    創作者 PG Levin Li 的頭像
    PG Levin Li

    程式開發學習之路

    PG Levin Li 發表在 痞客邦 留言(0) 人氣()