blob: e8e5c71e1420068e9a063e3d7ef5c7a813eab231 (
plain) (
blame)
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
|
package org.eclipse.team.tests.ccvs.ui;
/*
* (c) Copyright IBM Corp. 2000, 2001.
* All Rights Reserved.
*/
import java.util.Random;
/**
* Encapsulates algorithms and state for generating deterministic sequences.
* The sequence of numbers generated will always follow the same pattern,
* regardless of the time, place, or platform.
*/
public class SequenceGenerator {
private static long globalSeqNum = System.currentTimeMillis() * 1000;
private final Random random;
private int uniqueInt;
/**
* Constructs a new sequence generator with a known seed.
*/
public SequenceGenerator() {
random = new Random(3141592653589793238L); // a known constant
uniqueInt = 1000000;
}
/**
* Returns a globally unique long integer.
*/
public static long nextGloballyUniqueLong() {
return globalSeqNum++;
}
/**
* Returns a unique 7-digit integer.
*/
public int nextUniqueInt() {
return uniqueInt++;
}
/**
* Returns a pseudo-random integer between 0 and n-1.
* @see Random#nextInt(int)
*/
public int nextInt(int n) {
return random.nextInt(n);
}
/**
* Returns a pseudo-random real number following a gaussian distribution.
* @see Random#nextGaussian()
*/
public double nextGaussian() {
return random.nextGaussian();
}
}
|