Files
  • main.cpp
main.cpp
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <cmath>
#include <iomanip>
#include <chrono>
//our goal is to find random seeds that produce small values

using namespace std;

const long mod1  = 2147483563;
const long mod2  = 2147483399;
const long mult1 = 40014;
const long mult2 = 40692;
const long mult1sq = mult1 * mult1; // 1601120196

const long MAX_SEED = 1000000000 - 1;
const long ITERATIONS = 10;
long seed1,seed2;

void Seed(int n){
  if(n<0) //Perform an abs
    n = -n;
  if(n==0){
    seed1 = 12345; //Gotta love these seed values!
    seed2 = 67890;
  } else {
    seed1 = (mult1*n)%mod1;
    seed2 = n%mod2;
  }
}



long generate_long() {
    seed1  = (seed1*mult1) % mod1;
    seed2  = (seed2*mult2) % mod2;
    return seed1-seed2;
}


int generate_first(long s) {
    int x1 = (s*mult1sq) % mod1;
    int x2 = (s*mult2) % mod2;
    return x1 - x2;
}


double convert_01(long value) {
    double ret = (double) value / (double) mod1;
    if(ret < 0) ret += 1;
    return ret;
}

double Generate(){
    return convert_01(generate_long());
}

int main(){

    auto start = chrono::high_resolution_clock::now();
    long s;
    long inc1 = 0;
    long inc2 = 0;

    for(long s = 1; s < MAX_SEED; s ++) {

        Seed(s);
        for(int i = 1; i < ITERATIONS; i++) {

            int value = generate_long();
            if(abs(value) < 5) {
                cout << "seed = " << s <<
                    ", i = " << i <<
                    ", intvalue = " << value <<
                    ", floatvalue = " << setprecision(20) << convert_01(value) << endl;
            }
            }
    }
    
    auto elapsed = chrono::high_resolution_clock::now() - start;

    double seconds = ((double) std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count()) / 1000000;

    cout << "Time: " << seconds;


}

/*

Success with s = 0, x = 0
Success with s = 143697972, x = 7
Success with s = 144839781, x = -9
Success with s = 196164532, x = 0
Success with s = 339862504, x = 7
Success with s = 341004313, x = -9
Success with s = 392329064, x = 0
Success with s = 537168845, x = -9
Success with s = 588493596, x = 0
Success with s = 733333377, x = -9
Success with s = 784658128, x = 0
Success with s = 929497909, x = -9
Success with s = 980822660, x = 0
Time to 5*10^8: 28.4657   */
gcc version 4.6.3