-
-
Save pathologicalhandwaving/3a6db832ca69c7a0a281 to your computer and use it in GitHub Desktop.
Linear Feedback Shift Register Based uniform random number generator ... it generates 2**32 -1 random numbers
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
#include<iostream> | |
using namespace std; | |
int rand_gen(unsigned int x) { | |
/* | |
XOR Linear feedback shift register based random gen | |
*/ | |
unsigned int a=1; | |
unsigned int c=0,d=0,e=0; | |
c = x&a; | |
d = (x>>1) & a; | |
x >>= 1; | |
x |= ((c^d)<<31); | |
return x; | |
} | |
int main() { | |
unsigned int x=1; | |
int i; | |
for (i=0;i<135;i++) | |
{ | |
x = rand_gen(x); | |
cout<<"random="<<x<<endl; | |
} | |
return(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment