Imported Debian patch 0.12.7-3
[bowtie.git] / random_test.cpp
1 /*
2  * random_test.cpp
3  *
4  *  Created on: Dec 11, 2009
5  *      Author: Ben Langmead
6  */
7
8 #include <iostream>
9 #include <string.h>
10 #include "random_source.h"
11
12 using namespace std;
13
14 int main(void) {
15         RandomSource rand;
16         rand.init(0);
17         uint32_t ts[32];
18         memset(ts, 0, 32*sizeof(uint32_t));
19         uint32_t r = rand.nextU32();
20         cout << "Without reseeding:" << endl;
21         for(int i = 0; i < 10000; i++) {
22                 uint32_t nr = rand.nextU32();
23                 for(int j = 0; j < 32; j++) {
24                         if(((r >> j) & 1) != ((nr >> j) & 1)) {
25                                 ts[j]++;
26                         }
27                 }
28         }
29         for(int j = 0; j < 32; j++) {
30                 cout << ts[j] << endl;
31         }
32         memset(ts, 0, 32*sizeof(uint32_t));
33         rand.init(0);
34         r = rand.nextU32();
35         cout << "With reseeding:" << endl;
36         for(int i = 0; i < 10000; i++) {
37                 rand.init(i+1);
38                 uint32_t nr = rand.nextU32();
39                 for(int j = 0; j < 32; j++) {
40                         if(((r >> j) & 1) != ((nr >> j) & 1)) {
41                                 ts[j]++;
42                         }
43                 }
44         }
45         for(int j = 0; j < 32; j++) {
46                 cout << ts[j] << endl;
47         }
48 }