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

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
The Register - Security
The Register - Security
S
Secure Thoughts
有赞技术团队
有赞技术团队
Hacker News - Newest:
Hacker News - Newest: "LLM"
月光博客
月光博客
Engineering at Meta
Engineering at Meta
www.infosecurity-magazine.com
www.infosecurity-magazine.com
WordPress大学
WordPress大学
N
News | PayPal Newsroom
F
Fortinet All Blogs
Forbes - Security
Forbes - Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Y
Y Combinator Blog
L
LINUX DO - 最新话题
Google Online Security Blog
Google Online Security Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
阮一峰的网络日志
阮一峰的网络日志
Application and Cybersecurity Blog
Application and Cybersecurity Blog
V2EX - 技术
V2EX - 技术
H
Heimdal Security Blog
G
Google Developers Blog
Vercel News
Vercel News
Martin Fowler
Martin Fowler
TaoSecurity Blog
TaoSecurity Blog
腾讯CDC
Cyberwarzone
Cyberwarzone
罗磊的独立博客
S
Securelist
T
Tor Project blog
Recorded Future
Recorded Future
小众软件
小众软件
Attack and Defense Labs
Attack and Defense Labs
L
LINUX DO - 热门话题
The Cloudflare Blog
爱范儿
爱范儿
S
Security @ Cisco Blogs
雷峰网
雷峰网
Schneier on Security
Schneier on Security
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
S
Schneier on Security
大猫的无限游戏
大猫的无限游戏
Recent Announcements
Recent Announcements
Blog — PlanetScale
Blog — PlanetScale
D
Docker
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
酷 壳 – CoolShell
酷 壳 – CoolShell
Latest news
Latest news
M
MIT News - Artificial intelligence

博客园 - wj-conquer

Oracle数据库管理员面试题 dl, dt, dd标签的使用方法 新年到了, 写了几个网页祝福大家新年快乐, 万事如意 java根据自定义标记分割字符串 word2007中批量添加超链接的方法 如何使用freemarker将jsp网页静态化? jsp获取相对路径网址的方法 request.getContextPath() 百度广告联盟号被封 网站被降权 SQLServer如何取得随机获取的数据库记录 IE出问题,所有网页提示脚本错误 CSS使文章自动换行的问题 很精美的仿京东商城产品详细JS放大效果 JSP面试题及答案 四大方法提升百度联盟点击率 在页面中显示系统当前时间,在页面中加载时间 Unable to load configuration. - bean struts-default.xml struts2中的jar包冲突 设置首页 加入收藏代码 百度搜索引擎的代码、百度搜索功能的码代 Java调用SQL Server存储过程同时返回参数和结果集
Java中随机数生成, Manth和Random的用法
wj-conquer · 2012-07-08 · via 博客园 - wj-conquer

 

1、Math库里的static(静态)方法random()

  该方法的作用是产生0到1之间(包括0,但不包括1)的一个double值。

	double rand = Math.random();

2、通过Random类的对象

  程序可生成许多不同类型的随机数字,做法很简单,只需调用方法nextInt()和nextFloat()即可(也可以调用nextLong()或者nextDouble())。传递给nextInt()的参数设置了所产生随机数的上限,而其下限为0.

  如果在创建Random对象过程中没有传递任何参数,那么Java就会将当前时间作为随机数生成器的种子,并由此在程序每一次执行时都产生不同的输出。如果在创建Random对象时提供种子(用于随机数生成器的初始化值,随机数生成器对于特定的种子值总是产生相同的随机数序列),就可以在每一次执行程序时都生成相同的随机数,因此其输出是可验证的。

举例:生成1到1000之间的随机数

	import java.util.Random;

public class Radom{
    public static void main(String[] strs){
        Random rand = new Random();
        System.out.println(rand.nextInt(999)+1);
    }
}

设定种子,下例中的种子可以随便设定: