惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
云风的 BLOG
云风的 BLOG
G
Google Developers Blog
S
SegmentFault 最新的问题
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
爱范儿
爱范儿
博客园 - 三生石上(FineUI控件)
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
DataBreaches.Net
F
Fortinet All Blogs
TaoSecurity Blog
TaoSecurity Blog
D
Docker
C
Cybersecurity and Infrastructure Security Agency CISA
K
Kaspersky official blog
宝玉的分享
宝玉的分享
腾讯CDC
Google Online Security Blog
Google Online Security Blog
Recorded Future
Recorded Future
T
The Exploit Database - CXSecurity.com
T
The Blog of Author Tim Ferriss
V
V2EX
S
Securelist
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
CERT Recently Published Vulnerability Notes
A
Arctic Wolf
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
Y
Y Combinator Blog
P
Proofpoint News Feed
T
Tor Project blog
AWS News Blog
AWS News Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
博客园 - 聂微东
T
Threat Research - Cisco Blogs
B
Blog
Attack and Defense Labs
Attack and Defense Labs
L
Lohrmann on Cybersecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
N
News and Events Feed by Topic
博客园 - 司徒正美
H
Help Net Security
C
Cisco Blogs
C
Check Point Blog
S
Secure Thoughts

博客园 - 挖豆

关于iframe的滚动条,如何去掉水平滚动条或垂直滚动条 javascript得到网址中传递的参数 的处理函数 页面的焦点:window.onfocus 实现随页面滚动的层(最简单效果) 如何用代码设置滚动条的位置? javascript 网页注册快捷键的函数 关于javascript和c#中日期的两点比较--以防在使用ajax时出错 CSS中的overflow css实现圆角 关于Ajax.net 操作和访问 session application request ajax.net 的使用方法--摘自网上 ArrayList用法 最全的DOS命令集. 如何写批处理文件 读取数据库表的列名,表列的数据类型 在.NET中用MICROSOFT的Excel.Application 部件读取Excel表 ASP内置对象详细介绍 提供一个专业提供连接字符串的网站 Excel连接字符串
javascript 实现随机数 解析
挖豆 · 2007-08-30 · via 博客园 - 挖豆

Math对象中的方法
       Math.random() 该方法返回一个0到1之间的随机数,不包括0和1。
  要实现获得一个maxNumber到minNumber范围内的随机整数,实现方法如下:
       choNumber=maxNumber-minNumber+1;
       number=Math.floor(Math.random()*choNumber+minNumber)
                   
  例:
      选择一个1到10之间的随机数:
            number=Math.floor(Math.random()*10+1);
      可能出现的值有10个,最小的值为1。
     选择一个2到10之间的随机数:
            number=Math.floor(Math.random()*9+2);
      可能出现的值有9个,最小的值为2。
解释:Math.floor()用来获取一个整数,将小数转换成整数。

通过函数实现从一个数组中随机选择一个值:
  实现selectFrom()函数获得一个iFirstValue到iLastValue之间的随机整数
function selectFrom(iFirstValue,iLastValue)
        {
            var iChoices=iLastValue-iFirstValue+1;
             return Math.floor(Math.random()*iChoices+iFirstValue);
        }

例:

   var aColors=["red","green","yellow","black","blue","purple","brown"];
  var sColors=aColors[selectFrom(0,aColors.length-1)]