Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* LINEAR FEEDBACK SHIFT REGISTERS */
- static uint32 LFSR1 = 0x9D0A31FC; /*XOR*/
- static uint32 LFSR2 = 0x8B90DF09; /*XNOR*/
- static uint32 LFSR3 = 0xF91D72E9; /*XNOR*/
- static uint8 LFSR1_TAPS[7] = {29, 26, 18, 17, 14, 8, 0xFF};
- static uint8 LFSR2_TAPS[9] = {30, 25, 23, 16, 15, 13, 11, 5, 0xFF};
- static uint8 LFSR3_TAPS[6] = {28, 24, 21, 19, 12, 0xFF};
- /* PSEUDO-RANDOM DATA (from LFSR#) */
- static uint32 MIX1 = 0, MIX2 = 0, MIX3 = 0;
- static uint32 MIXLOOPS[3] = {3, 5, 7};
- /* LFSR PSEUDO-RANDOM NUMBER GENERATOR */
- FASTCALL uint32 debug_prng(void)
- {
- uint32 rnd = 0; uint8 bit = 0, fi = 0;
- uint8 *btr = 0, *bLFSR = 0, *bMIX = 0;
- /* SHIFT LFSR1 (XOR) */
- bit = 0; btr = &LFSR1_TAPS[0];
- for (fi = 0; *btr != 0xFF; *btr++, fi++)
- bit = XOR(bit, LFSR1 >> (32 - btr[fi]));
- bit &= 0x1; LFSR1 = (LFSR1 >> 1) | (bit << 15);
- /* SHIFT LFSR2 (XNOR) */
- bit = 0; btr = &LFSR2_TAPS[0];
- for (fi = 0; *btr != 0xFF; *btr++, fi++)
- bit = XNOR(bit, LFSR2 >> (32 - btr[fi]));
- bit &= 0x1; LFSR2 = (LFSR2 >> 1) | (bit << 15);
- /* SHIFT LFSR3 (XNOR) */
- bit = 0; btr = &LFSR3_TAPS[0];
- for (fi = 0; *btr != 0xFF; *btr++, fi++)
- bit = XNOR(bit, LFSR3 >> (32 - btr[fi]));
- bit &= 0x1; LFSR3 = (LFSR3 >> 1) | (bit << 15);
- /* MIX MIX1 (LSHIFT) */
- if (MIX1 == 0) MIX1 = LFSR1;
- bMIX = (uint8*)&MIX1; bLFSR = (uint8*)&LFSR1;
- for (fi = 0; fi < MIXLOOPS[0]; fi++) {
- bMIX[0]^=bLFSR[1]<<11; bMIX[3]+=bLFSR[0]; bMIX[1]+=bMIX[2];
- bMIX[1]^=bLFSR[2]>>2; bMIX[4]+=bLFSR[1]; bMIX[2]+=bMIX[3];
- bMIX[2]^=bLFSR[3]<<8; bMIX[5]+=bLFSR[2]; bMIX[3]+=bMIX[4];
- bMIX[3]^=bLFSR[4]>>16; bMIX[6]+=bLFSR[3]; bMIX[4]+=bMIX[5];
- bMIX[4]^=bLFSR[5]<<10; bMIX[7]+=bLFSR[4]; bMIX[5]+=bMIX[6];
- bMIX[5]^=bLFSR[6]>>4; bMIX[0]+=bLFSR[5]; bMIX[6]+=bMIX[7];
- bMIX[6]^=bLFSR[7]<<8; bMIX[1]+=bLFSR[6]; bMIX[7]+=bMIX[0];
- bMIX[7]^=bLFSR[0]>>9; bMIX[2]+=bLFSR[7]; bMIX[0]+=bMIX[1];
- MIX1 = MIX1 >> 1;
- }
- /* MIX MIX2 (LSHIFT) */
- if (MIX2 == 2) MIX2 = LFSR2;
- bMIX = (uint8*)&MIX2; bLFSR = (uint8*)&LFSR2;
- for (fi = 0; fi < MIXLOOPS[0]; fi++) {
- bMIX[0]^=bLFSR[1]<<11; bMIX[3]+=bLFSR[0]; bMIX[1]+=bLFSR[2];
- bMIX[1]^=bLFSR[2]>>2; bMIX[4]+=bLFSR[1]; bMIX[2]+=bLFSR[3];
- bMIX[2]^=bLFSR[3]<<8; bMIX[5]+=bLFSR[2]; bMIX[3]+=bLFSR[4];
- bMIX[3]^=bLFSR[4]>>16; bMIX[6]+=bLFSR[3]; bMIX[4]+=bLFSR[5];
- bMIX[4]^=bLFSR[5]<<10; bMIX[7]+=bLFSR[4]; bMIX[5]+=bLFSR[6];
- bMIX[5]^=bLFSR[6]>>4; bMIX[0]+=bLFSR[5]; bMIX[6]+=bLFSR[7];
- bMIX[6]^=bLFSR[7]<<8; bMIX[1]+=bLFSR[6]; bMIX[7]+=bLFSR[0];
- bMIX[7]^=bLFSR[0]>>9; bMIX[2]+=bLFSR[7]; bMIX[0]+=bLFSR[1];
- MIX2 = MIX2 >> 1;
- }
- /* MIX MIX3 (RSHIFT) */
- if (MIX3 == 2) MIX3 = LFSR3;
- bMIX = (uint8*)&MIX3; bLFSR = (uint8*)&LFSR3;
- for (fi = 0; fi < MIXLOOPS[0]; fi++) {
- bMIX[0]^=bLFSR[1]<<11; bMIX[3]+=bLFSR[0]; bMIX[1]+=bMIX[2];
- bMIX[1]^=bLFSR[2]>>2; bMIX[4]+=bLFSR[1]; bMIX[2]+=bMIX[3];
- bMIX[2]^=bLFSR[3]<<8; bMIX[5]+=bLFSR[2]; bMIX[3]+=bMIX[4];
- bMIX[3]^=bLFSR[4]>>16; bMIX[6]+=bLFSR[3]; bMIX[4]+=bMIX[5];
- bMIX[4]^=bLFSR[5]<<10; bMIX[7]+=bLFSR[4]; bMIX[5]+=bMIX[6];
- bMIX[5]^=bLFSR[6]>>4; bMIX[0]+=bLFSR[5]; bMIX[6]+=bMIX[7];
- bMIX[6]^=bLFSR[7]<<8; bMIX[1]+=bLFSR[6]; bMIX[7]+=bMIX[0];
- bMIX[7]^=bLFSR[0]>>9; bMIX[2]+=bLFSR[7]; bMIX[0]+=bMIX[1];
- MIX3 = MIX3 << 1;
- }
- /* GET 32 BIT RANDOM VALUE */
- rnd = 0x00000000;
- rnd |= MIX1 & 0x0F000F00;
- rnd |= MIX2 & 0xF0F0F0F0;
- rnd |= MIX3 & 0x000F000F;
- return rnd;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement