vendredi 23 octobre 2015

C++ How to input random 4-bit and output random 64-bits?

Define G(s) as follows. The seed s is a starting state for the LFSR. This is a truly random 4-bit value. We produce G(s) by letting the LFSR generate 64 bits of output. Thus l=64 and n=4 in this case.

I'm doing an assignment using an LFSR. I have the code to shift the 4-bit binary string. However, it's not random and it needs to be input into a function that then outputs a random 64-bit string. How do I change it to make the 4-bit random and pass it trough a function?

Here's my code so far.

#include <iostream>
#include <bitset>
using namespace std;
int main() 
{
int x = 6;      // Binary 0110
int y = 0;
int count = 0;

std::bitset<4> lfsr(x);
std::bitset<4> bit(y);


do
{
    cout << "lfsr: " <<lfsr << endl;
    bit  = ((lfsr >> 0) ^ (lfsr >> 2));
    lfsr = (lfsr >> 1) | (bit << 3);
    ++count;
} while (count < 4);

system("pause");
return 0;
}




Aucun commentaire:

Enregistrer un commentaire