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
|
#include <random>
#include <iostream>
#include <ctime>
#include <vector>
#include <cmath>
using namespace std;
int main()
{
typedef unsigned long ulong_t;
// seed_seq initializaiton
const ulong_t nums[] = {1,2,3,4,5,6,7,8,9,10};
seed_seq seq(nums, nums + 9);
// generating sequence for example
vector<ulong_t> set;
seq.generate(set.begin(), set.end());
// engines typedefing
typedef mersenne_twister_engine<ulong_t, 32, 624, 397, 31,
0x9908b0df, 11,
0xffffffff, 7,
0x9d2c5680, 15,
0xefc60000, 18,
1812433253> twist;
typedef linear_congruential<ulong_t, 44, 499, 30> gen;
typedef subtract_with_carry<ulong_t, 50, 33, 8> sub;
// creating engines
independent_bits_engine<knuth_b, 25, ulong_t> fin;
shuffle_order_engine<ranlux24, 333> fin2;
discard_block_engine<twist, 99, 94009> fin3;
// start seeding
fin.seed(seq);
fin2.seed(seq);
fin3.seed(seq);
// distribution declaration
uniform_int_distribution<ulong_t> dist(3, 37);
exponential_distribution<float> dist2(exp(1));
bernoulli_distribution ber(.7);
// Output
cout << "knuth_b " << '\t' << "ranlux24 " << "twist" << endl;
for (short i = 0; i < 30; i++)
{
clock_t stop = clock() + .5 * CLOCKS_PER_SEC;
while (clock() < stop);
cout << dist( fin3 ) << "\t\t" << dist2( fin2 ) << "\t\t" << ber( fin3 ) << endl;
}
// end of code
cout << "\nExecution done...";
std::cin.get();
return 0;
}
|