"Random" Circuit Needed.
On 2015-04-29, David Eather wrote:
On Tue, 28 Apr 2015 17:15:27 +1000, Jasen Betts wrote:
On 2015-04-27, Bob Masta wrote:
On Sun, 26 Apr 2015 09:32:00 -0400, rickman
wrote:
snip
Really? There are many ways of generating PRS. There are trade-offs
with each one. If you don't need the speed or small size an LFSR has
disadvantages compared to many others.
I hesitate to get into this, err, "discussion", but in
software at least, an LFSR has one nifty advantage over the
simpler and more-common linear congruential approach: You
can run it backwards!
You can run a linear congruential backwards it's just a matter of
using different factor and addend constants.
I've never seen that. I would like to.
#include stdio.h
unsigned int seed=1;
/* a common LC random */
unsigned int rand(void){
seed= ((long long) seed*1103515245 + 12345 ) &0xfffffffful;
return seed;
}
/* the inverse */
unsigned int unrand(void){
seed=((long long) seed *4005161829 + 4235699843) &0xfffffffful ;
return seed;
}
/*
4005161829 above is the reciprocal of 1103515245 mod 2^32
knowing that multiplication by 1103515245 would have a period of 2^32
in mod 2^32
I asked wolfram alpha "1103515245 ^4294967295 mod 4294967296"
4235699843 above is the additive inverse of 12345 * 4005161829 mod 2^32
I asked wolfram alpha
"4294967296 - (( 12345 * 4005161829 ) mod 4294967296 )"
modular arithmetic is crazy stuff...
*/
main(){
int x;
printf("%10u ",seed); printf(" %10u\n", rand());
printf("%10u ",seed); printf(" %10u\n", rand());
printf("%10u ",seed); printf(" %10u\n", rand());
printf("%10u ",seed); printf(" %10u\n", rand());
printf("%10u ",seed); printf(" %10u\n", rand());
printf("%10u ",seed); printf(" %10u\n", rand());
printf("--------------------\n");
printf("%10u ",seed); printf(" %10u\n", unrand());
printf("%10u ",seed); printf(" %10u\n", unrand());
printf("%10u ",seed); printf(" %10u\n", unrand());
printf("%10u ",seed); printf(" %10u\n", unrand());
printf("%10u ",seed); printf(" %10u\n", unrand());
printf("%10u ",seed); printf(" %10u\n", unrand());
printf("--------------------\n");
seed=8008135;
printf("%10u ",seed);
for( x=1; x 10000000; ++x ) rand();
printf("%10u\n",seed);
printf("%10u ",seed);
for( x=1; x 10000000; ++x ) unrand();
printf("%10u\n",seed);
return 0;
}
--
umop apisdn
|