本文實例講述了JS簡單隨機數生成方法。分享給大家供大家參考,具體如下:
<!doctype html><html><head><meta charset="utf-8"><title>隨機數</title></head><body><script type="text/javascript">function Randnum(value){ var s=1000; var d=500; if(value=='b'){ document.write(s+parseInt(500*Math.random())); }else{ document.write(d+parseInt(500*Math.random())); }}</script><script>Randnum();</script></body></html>效果圖:

更多關于JavaScript算法相關內容感興趣的讀者可查看本站專題:《JavaScript數學運算用法總結》、《JavaScript排序算法總結》、《JavaScript遍歷算法與技巧總結》及《JavaScript數據結構與算法技巧總結》
希望本文所述對大家JavaScript程序設計有所幫助。
新聞熱點
疑難解答