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

推荐订阅源

爱范儿
爱范儿
T
The Blog of Author Tim Ferriss
G
Google Developers Blog
博客园_首页
博客园 - 【当耐特】
量子位
S
SegmentFault 最新的问题
B
Blog RSS Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
V
Visual Studio Blog
T
Tailwind CSS Blog
阮一峰的网络日志
阮一峰的网络日志
V
V2EX
Y
Y Combinator Blog
博客园 - 聂微东
The Cloudflare Blog
小众软件
小众软件
J
Java Code Geeks
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
月光博客
月光博客
H
Help Net Security
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
宝玉的分享
宝玉的分享

博客园 - 郄永军

用触发器实现表的同步操作 Quartz CronTrigger最完整配置说明 - 郄永军 - 博客园 如何优化JAVA程序开发,提高JAVA性能 使用Hibernate+Middlegen实现自动代码生成简介 如何用java调用c++编写成的DLL Web.xml加载顺序 java性能优化 Java NIO简介 选用ibatis和hibernate的区别 Fusioncharts 参数 dwr介绍 ASP.NET缓存:方法分析和实践示例 比较同一数据库不同版本间数据表之间差异 如何动态执行存储过程或函数 NTKO正文控件的使用技巧 - 郄永军 - 博客园 Dorado开发框架下保存附件存草稿功能 - 郄永军 - 博客园 JS中的关于类型转换的性能优化 - 郄永军 - 博客园 如何把ini文件转换为xml 获取文件大小的java程序
生成随即的数值
郄永军 · 2010-12-14 · via 博客园 - 郄永军

代码

 1 Random rand = new Random();
 2 
 3 // Random integers
 4 int i = rand.nextInt();
 5 // Continually call nextInt() for more random integers ...
 6 
 7 // Random integers that range from from 0 to n
 8 int n = 10;
 9 = rand.nextInt(n+1);
10 
11 // Random bytes
12 byte[] bytes = new byte[5];
13 rand.nextBytes(bytes);
14 
15 // Other primitive types
16 boolean b = rand.nextBoolean();
17 long l = rand.nextLong();
18 float f = rand.nextFloat();     // 0.0 <= f < 1.0
19 double d = rand.nextDouble();   // 0.0 <= d < 1.0
20 
21 
22 // Create two random number generators with the same seed
23 long seed = rand.nextLong();
24 rand = new Random(seed);
25 Random rand2 = new Random(seed);
26