-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
langmead
committed
Dec 11, 2009
1 parent
c649ca4
commit d70351d
Showing
2 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} | ||
} |