Re: 8 Bit Random Numbers



On Feb 4, 2:14 am, Nobody <nob...@xxxxxxxxxxx> wrote:

For your original sequence of 3,4,5,7, use 0xB8 or 0x1D, depending upon
the shift direction. The following C code generates the same bit sequence
using both Fibonacci and Galois implementations.

Note that the two versions generate the same bit sequences, but the
sequence of 8-bit states differs.

#include <stdio.h>

typedef unsigned char byte;

byte f_taps = 0x1D; /* 0001 1101 */
byte g_taps = 0xB8; /* 1011 1000 */

byte xor(byte x)
{
x = (x & 0x0F) ^ (x >> 4);
x = (x & 0x03) ^ (x >> 2);
x = (x & 0x01) ^ (x >> 1);
return x;

}

byte f(byte *x)
{
byte t = xor(*x & f_taps);
*x >>= 1;
*x |= t << 7;
return t;

}

byte g(byte *x)
{
byte t = *x & 1;
byte k = (-t) & g_taps;
*x >>= 1;
*x ^= k;
return t;

}

int main(void)
{
byte x = 1, y = 1;
int i;

for (i = 0; i < 0x100; i++) {
byte tx = f(&x);
byte ty = g(&y);
printf("%d %d\n", tx, ty);
}

return 0;

}


Thanks for the C code, but my knowledge of C is limited, and it may be
a little slow to implement.

I found an assembly program for a PIC processor on the web which
requires 10 lines of code, or maybe 44 clock cycles.

The idea is to shift the random register left and obtain the result in
the working register (w) and then shift the register again which rolls
around the carry bit to the first bit, again in (w). Then the three
feedback bits are tested to determine the new input bit and the result
fed to the lowest bit.

Looks pretty speedy, but I was thinking the parallel approach might
reduce the 44 clocks to a lower number.

What I'm not understanding with the parallel approach is how the 8 bit
result from xoring a constant 8 bits is converted to a single bit to
be shifted into the register. In other words, if I xor
B8 with the contents of the random register, I get some new 8 bit
number. What can I do with that? How does the new 8 bit result resolve
to a single bit?

Main:

RLF RANDOM,0
RLF RANDOM,0
BTFSC RANDOM,3
XORLW 1
BTFSC RANDOM,4
XORLW 1
BTFSC RANDOM,5
XORLW 1
MOVWF RANDOM
GOTO Main



-Bill
.



Relevant Pages

  • Re: Multiplexing - how to speed up
    ... Currently I'm testing with 5 cascaded shift registers (serial in, ... After adding the 5th shift register the image started flickering. ... void shift_byte ... internal buffer but not to the output pins of that register. ...
    (sci.electronics.design)
  • Bits!
    ... in a sequence of four bytes, ... patterns to accomplish the needed work of various bitstream access ... Instead of considering only a single register of the computer at a time, ... where the data is msb to lsb in bit order, and MSB to LSB in byte order, ...
    (comp.lang.asm.x86)
  • Re: Variadic functions calling variadic functions with the argument list, HLL bit shifts on LE proce
    ... >to file or stream as a sequential sequence of bytes. ... you have to deal with the bytes in the ENDIAN ORDER THEY ... >at once onto the register. ... >So anyways, a point here is that on the little-endian machine, when the ...
    (comp.lang.c)
  • Re: Multiplexing - how to speed up
    ... Currently I'm testing with 5 cascaded shift registers (serial in, ... After adding the 5th shift register the image started flickering. ... void shift_byte ...
    (sci.electronics.design)
  • Re: device for converting binary strings into states for switches
    ... For 8 switches I think that I got the idea, ... into a register). ... you need a serial-to-parallel shift ... register clock and the latch clock. ...
    (sci.electronics.basics)