/* Random number Generator using LFSR Dhananjay V. Gadre 8 bit LFSR Taps at 1, 2, 3 and 8 runs under linux, unix. compile as: gcc filename.c -o executablefilename */ #include #include #include #include #include #define true 1 #define false 0 int main(argc, argv) int argc; char *argv[]; { int value, temp, temp1, temp2, tap1, tap2, tap3, tap4; if(argc != 2) {printf("\nError... Specify a seed. Aborting"); printf("\nFormat: %s seed[a number]\n", argv[0]); exit(-1); } value=atoi(argv[1]); /*read in the seed with which to init the LFSR*/ printf("\nSeed = %d\n", value); value = value & 0x7f; for(temp1=0; temp1 < 0x100; temp1 ++) { temp=value; tap1 = temp & 0x02; tap2 = temp & 0x04; tap3 = temp & 0x08; tap4 = temp & 0x80; tap1 = tap1 >> 1; tap2 = tap2 >> 2; tap3 = tap3 >> 3; tap4 = tap4 >> 7; temp2 = (tap1 ^ tap2) ^ (tap3 ^ tap4); /*shift the LFSR left*/ value = value << 1; /*if the XOR result is 0, set bit 0 to 0 else set it to 1*/ if(temp2 == 0) (value = value & 0xfffe); else value = value | 0x0001; printf("%x ", 0xff & value); /*just look at the last 8 bits*/ } return true; }