-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathPSNG.java
More file actions
33 lines (24 loc) · 746 Bytes
/
PSNG.java
File metadata and controls
33 lines (24 loc) · 746 Bytes
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
package ds_001_intro;
public class PSNG {
private static final int CONSTANT_A = 5;
private static final int CONSTANT_B = 3;
private static final int MODULO = 7;
public static void main(String[] args) {
printPseudoRandomNumber(6);
}
private static int generatePseudoRandomNumber(int prevNum, int constNumA, int constNumB, int modulo) {
if(prevNum == Integer.MIN_VALUE) {
return 0;
}
return (prevNum*constNumA + constNumB)%modulo;
}
private static void printPseudoRandomNumber(int n) {
int prev = Integer.MIN_VALUE;
int next;
for(int i = 0; i <= n; i++) {
next = generatePseudoRandomNumber(prev, CONSTANT_A, CONSTANT_B, MODULO);
prev = next;
System.out.printf("[%2d]: %d\n", i, next);
}
}
}