File: random_test.cpp

package info (click to toggle)
bowtie 1.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 14,864 kB
  • ctags: 5,533
  • sloc: cpp: 32,737; perl: 2,084; ansic: 1,241; sh: 1,066; makefile: 344; python: 133
file content (48 lines) | stat: -rw-r--r-- 933 bytes parent folder | download | duplicates (7)
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
/*
 * random_test.cpp
 *
 *  Created on: Dec 11, 2009
 *      Author: Ben Langmead
 */

#include <iostream>
#include <string.h>
#include "random_source.h"

using namespace std;

int main(void) {
	RandomSource rand;
	rand.init(0);
	uint32_t ts[32];
	memset(ts, 0, 32*sizeof(uint32_t));
	uint32_t r = rand.nextU32();
	cout << "Without reseeding:" << endl;
	for(int i = 0; i < 10000; i++) {
		uint32_t nr = rand.nextU32();
		for(int j = 0; j < 32; j++) {
			if(((r >> j) & 1) != ((nr >> j) & 1)) {
				ts[j]++;
			}
		}
	}
	for(int j = 0; j < 32; j++) {
		cout << ts[j] << endl;
	}
	memset(ts, 0, 32*sizeof(uint32_t));
	rand.init(0);
	r = rand.nextU32();
	cout << "With reseeding:" << endl;
	for(int i = 0; i < 10000; i++) {
		rand.init(i+1);
		uint32_t nr = rand.nextU32();
		for(int j = 0; j < 32; j++) {
			if(((r >> j) & 1) != ((nr >> j) & 1)) {
				ts[j]++;
			}
		}
	}
	for(int j = 0; j < 32; j++) {
		cout << ts[j] << endl;
	}
}