static unsigned long
x=123456789,y=362436069,z=
/* replace defaults with five random seed values in calling program */
unsigned long xorshift(void)
{unsigned long t;
t=(x^(x>>7)); x=y; y=z; z=w; w=v;
v=(v^(v<<6))^(t^(t<<13)); return (y+y+1)*v;}
#include <stdint.h>
int main(void)
{
uint32_t lfsr = 1;
unsigned period = 0;
do
{
/* taps: 32 31 29 1; feedback polynomial: x^32 + x^31 + x^29 + x + 1 */
lfsr = (lfsr >> 1) ^ (-(lfsr & 1u) & 0xD0000001u);
++period;
} while(lfsr != 1u);
return 0;
}
seed=15239;
for (i=0;i<1000;i++){
seed =(86028157*seed + 142501)%1299689;
rand=seed/1299689;
print(rand);
}
Or the following if using type int.seed=43;
for (i=0;i<1000;i++){
seed =(5171*seed + 142501)%34421
rand=seed/34421;
print(rand);
}
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
In Notepad++ is there a way to find the set of characters displayed in the attached file? | 4 | 37 | |
Does a rhombus have 2 pairs of parallel sides | 5 | 41 | |
Auto Adjust Percent rate | 5 | 31 | |
Best resource to learn entity framework | 2 | 11 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
22 Experts available now in Live!