Skip to content

Instantly share code, notes, and snippets.

@wtfaremyinitials
Created November 21, 2016 15:07
Show Gist options
  • Save wtfaremyinitials/713b716fa1913e9aa76af65177eaa1af to your computer and use it in GitHub Desktop.
Save wtfaremyinitials/713b716fa1913e9aa76af65177eaa1af to your computer and use it in GitHub Desktop.
#include <iostream>
#include <iomanip>
using namespace std;
/*
0: 50
1: 54
3: 57
6: 59
62: 61
166: 63
196: 64
556: 67
7205: 69
38930: 70
111659: 73
1044302: 74
7305337: 75
19320394: 76
57954684: 77
207504137: 78
771076049: 79
*/
long mod1 = 2147483563;
long mod2 = 2147483399;
long mult1 = 40014;
long mult2 = 40692;
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;
}
}
double Generate(){
double result;
seed1 = (seed1*mult1)%mod1;
seed2 = (seed2*mult2)%mod2;
result = (double)(seed1-seed2)/(double)mod1;
if(result<0)
result = result+1;
return result;
}
int trial(int seed) {
Seed(seed);
int c = 0;
for(int i=0; i<100; i++) {
c += (Generate()>0.5);
}
return c;
}
int main(){
int max = 0;
for(int i=0;1;i++) {
int n = trial(i);
if(n > max) {
cout<<i<<": "<<n<<endl;
max = n;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment