-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomTest.java
More file actions
63 lines (53 loc) · 1.99 KB
/
RandomTest.java
File metadata and controls
63 lines (53 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package io.github.hooj0.system;
import io.github.hooj0.BasedTests;
import java.util.Arrays;
import java.util.Random;
/**
* 随机测试
*
* @author hoojo
* @version 1.0
* @date 13, 2011 8:55:08 PM
*/
public class RandomTest extends BasedTests {
public static void main(String[] args) {
Random rand = new Random();
out("rand.nextBoolean(): " + rand.nextBoolean());
byte[] bt = new byte[16];
rand.nextBytes(bt);
out(Arrays.toString(bt));
//生成0.0~1.0 之间的伪随机double数
out("rand.nextDouble(): " + rand.nextDouble());
//生成0.0~1.0 之间的伪随机float数
out("rand.nextFloat(): " + rand.nextFloat());
//生成平均值是0.0,标准差是1.0的伪高斯数
out("rand.nextGaussian(): " + rand.nextGaussian());
//生成一个处于int整数取值范围的伪随机数
out("rand.nextInt(): " + rand.nextInt());
//生成一个0~26之间的int整数取值范围的伪随机数
out("rand.nextInt(26): " + rand.nextInt(26));
//生成一个处于long整数取值范围的伪随机数
out("rand.nextLong(): " + rand.nextLong());
out("--------------------------------------");
rand = new Random(50);
out("种子为50的Random对象");
out("rand.nextBoolean(): " + rand.nextBoolean());
out("rand.nextInt(): " + rand.nextInt());
out("rand.nextDouble(): " + rand.nextDouble());
out("rand.nextGaussian(): " + rand.nextGaussian());
out("--------------------------------------");
rand = new Random(50);
out("种子为100的Random对象");
out("rand.nextBoolean(): " + rand.nextBoolean());
out("rand.nextInt(): " + rand.nextInt());
out("rand.nextDouble(): " + rand.nextDouble());
out("rand.nextGaussian(): " + rand.nextGaussian());
out("--------------------------------------");
rand = new Random(100);
out("种子为50的Random对象");
out("rand.nextBoolean(): " + rand.nextBoolean());
out("rand.nextInt(): " + rand.nextInt());
out("rand.nextDouble(): " + rand.nextDouble());
out("rand.nextGaussian(): " + rand.nextGaussian());
}
}