446,134 Members | 1,796 Online Need help? Post your question and get tips & solutions from a community of 446,134 IT Pros & Developers. It's quick & easy.

# Random Binary Sequence

 P: 2 Hello everyone! I'm searching for a Random Binary Sequence which creates the outcome of an XOR gate. I need to create a sequence of 2^(7) -1 bits....using my C compiler. Thank you all for your time... Jun 29 '06 #1
5 Replies

 Expert Mod 5K+ P: 8,916 Sorry ut that doesn't make sense to me, since XOR is definately not random I fail to see how a Random Binary Sequence could be the output of XOR. Perhaps you could explain the problem in more detail. Jun 30 '06 #2

 P: 2 Thanx for your interest. I need to create a Random Binary Sequence starting with four '1' (bits), that is to say 1 1 1 1. We now assume that the two last bits are inputs of an XOR gate. We calculate their outcome which is 0. The next sequence we receive is 0 1 1 1, which results from the movement of 0 into the first position and the movement of the three first bits by one position to the right, just like if we had a shift register. We are doing this procedure many times and at last we receive the last column. I mean that each time we need to keep only the last of the four bits. Now, if we need to receive 2^(7)-1 bits we must calculate 127 times the outcome of the XOR gate and receive each time the last bit, that is to say 127 bits. Hope not to ask too much!!!! I think that such a function exists on Basic, but I need to do it in C. Thanks again!!! :-) Jun 30 '06 #3

 100+ P: 293 The following code is a terrible way to do this, using only XOR for the booleans. There's a much nicer way to do it, I'll leave it up to you to figure out what the code is doing, and how to make it nicer. Expand|Select|Wrap|Line Numbers int main() {   bool input[] = {true,true,true,true};   int i;     for(i = 0; i < 127; i++)   {     input ^= input;     input ^= input;     input ^= input;     input ^= input;     input ^= input;     input ^= input;     input ^= input;     input ^= input;       if(input)       cout << "1";     else       cout << "0";   }   cout << endl;   system("PAUSE");   return EXIT_SUCCESS; } Ignoring the spaces, the result is: 000100110101111 repeated eight and a half times. I think chaotic is a better word than random. Jun 30 '06 #4

 Expert Mod 5K+ P: 8,916 OK well I think something like this is what you want Expand|Select|Wrap|Line Numbers #include "stdio.h"     int main(int argc, char* argv[]) {     unsigned char data = 0xff;     unsigned char result;     int ix;       for(ix=0;ix<127;ix++)     {         result = (data ^ ((data & 0x40) << 1)) & 0x80;           if ( result & 0x80 )         {             putchar('1');         }         else         {             putchar('0');         }           data = (data >> 1) | result;     }       putchar('\n');       return 0; }   But the results are not very random 01101101101101101101101101101101101101101101101101 10110110110110110110110110110110110110110110110110 110110110110110110110110110 As you can see. Jun 30 '06 #5

 Expert Mod 5K+ P: 8,916 Ignoring the spaces, the result is: 000100110101111 repeated eight and a half times. I think chaotic is a better word than random. Actually chaotic is a really poor word for it,a chaotic system never repeats which you admit yours does. Still trying to work out what your code actualy does though :D Jun 30 '06 #6 