Category : Files from Magazines
Archive   : DDJ0292.ZIP
Filename : RANDOM.ASC

 
Output of file : RANDOM.ASC contained in archive : DDJ0292.ZIP
_PSEUDO-RANDOM SEQUENCE GENERATOR FOR 32-BIT CPUs_
by Bruce Schneier


[LISTING ONE]


int RANDOM () {
static unsigned long register; /*Register must be unsigned so right
shift works properly.*/
/*Register should be initialized with some random value.*/
register = ((((register >> 31) /*Shift the 32nd bit to the first bit*/
^ (register >> 6) /*XOR it with the seventh bit*/
^ (register >> 4) /*XOR it with the fifth bit*/
^ (register >> 2) /*XOR it with the third bit*/
^ (register >> 1) /*XOR it with the second bit*/
^ register) /*and XOR it with the first bit.*/
& 0x0000001) /*Strip all the other bits off and*/
<<31) /*move it back to the 32nd bit.*/
| (register >> 1); /*Or with the register shifted right.*/
return register & 0x00000001; /*Return the first bit.*/
}




[LISTING TWO]


int VERYRANDOM () {
static unsigned long regA, regB, regC;
/*regA, regB, and regC should be initialized with some random value.*/
regA = ((((regA>>31)^(regA>>6)^(regA>>4)^(regA>>2)^(regA<<1)^regA)
& 0x00000001)<<31) | (regA>>1);
regB = ((((regB>>30)^(regB>>2)) & 0x00000001)<<30) | (regB>>1);
regC = ((((regC>>28)^(regC>>1)) & 0x00000001)<<28) | (regC>>1);
/*regB is a 31-bit LFSR. regC is a 29-bit LFSR.*/
/*Both feedback sequences are chosen to be maximum length.*/
return ((regA & regB) | (!regA & regC)) & 0x00000001;
/*Above is equivalant to: if A then return B else return C.*/
/* Variants: return ((regA & regB) | (regA & regC) | (regB & regC)) &
0x00000001; Above variant returns the majority of A, B, and C.
return (regA ^ regB ^ regC) & 0x00000001;
Above variant returns the XOR of A, B, and C. */
}



  3 Responses to “Category : Files from Magazines
Archive   : DDJ0292.ZIP
Filename : RANDOM.ASC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/