-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPoorRandomizer.jack
34 lines (28 loc) · 976 Bytes
/
PoorRandomizer.jack
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
class PoorRandomizer {
field Array multipliers;
field int currentIndex;
constructor PoorRandomizer new() {
let multipliers = Array.new(10);
let currentIndex = 0;
// ten palindromic primes 101, 131, 151, 181, 191, 313, 353, 373, 383, 727
let multipliers[0] = 101;
let multipliers[1] = 131;
let multipliers[2] = 151;
let multipliers[3] = 181;
let multipliers[4] = 191;
let multipliers[5] = 313;
let multipliers[6] = 353;
let multipliers[7] = 373;
let multipliers[8] = 383;
let multipliers[9] = 727;
return this;
}
method int getRandom(int seed, int max) {
var int num, random;
let num = seed * multipliers[currentIndex];
let random = num - (num / max * max);
let currentIndex = currentIndex + 1;
let currentIndex = currentIndex - (currentIndex / 10 * 10);
return random;
}
}