473,397 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Random Binary Sequence

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 6785
Banfa
9,065 Expert Mod 8TB
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
cboth
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
D_C
293 100+
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
  1. int main()
  2. {
  3.   bool input[] = {true,true,true,true};
  4.   int i;
  5.  
  6.   for(i = 0; i < 127; i++)
  7.   {
  8.     input[0] ^= input[1];
  9.     input[1] ^= input[0];
  10.     input[0] ^= input[1];
  11.     input[2] ^= input[3];
  12.     input[3] ^= input[2];
  13.     input[0] ^= input[2];
  14.     input[2] ^= input[0];
  15.     input[0] ^= input[2];
  16.  
  17.     if(input[0])
  18.       cout << "1";
  19.     else
  20.       cout << "0";
  21.   }
  22.   cout << endl;
  23.   system("PAUSE");
  24.   return EXIT_SUCCESS;
  25. }
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
Banfa
9,065 Expert Mod 8TB
OK well I think something like this is what you want

Expand|Select|Wrap|Line Numbers
  1. #include "stdio.h"
  2.  
  3.  
  4. int main(int argc, char* argv[])
  5. {
  6.     unsigned char data = 0xff;
  7.     unsigned char result;
  8.     int ix;
  9.  
  10.     for(ix=0;ix<127;ix++)
  11.     {
  12.         result = (data ^ ((data & 0x40) << 1)) & 0x80;
  13.  
  14.         if ( result & 0x80 )
  15.         {
  16.             putchar('1');
  17.         }
  18.         else
  19.         {
  20.             putchar('0');
  21.         }
  22.  
  23.         data = (data >> 1) | result;
  24.     }
  25.  
  26.     putchar('\n');
  27.  
  28.     return 0;
  29. }
  30.  
But the results are not very random

01101101101101101101101101101101101101101101101101 10110110110110110110110110110110110110110110110110 110110110110110110110110110

As you can see.
Jun 30 '06 #5
Banfa
9,065 Expert Mod 8TB
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

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: Thomas Mlynarczyk | last post by:
I remember there is a programming language where you can initialize the random number generator, so that it can - if you want - give you the exactly same sequence of random numbers every time you...
10
by: Sonoman | last post by:
Hi all: I am trying to write a simple program that simulates asking several persons their birth day and it counts how many persons are asked until two have the same birth day. The problem that I...
3
by: Joe | last post by:
Hi, I have been working on some code that requires a high use of random numbers within. Mostly I either have to either: 1) flip a coin i.e. 0 or 1, or 2) generate a double between 0 and 1. I...
25
by: JNY | last post by:
I am using random to generate random numbers, thus: int x,y; for (y = 0;y < 5;y++) { x = random(50); cout << x; }
1
by: steflhermitte | last post by:
Dear cpp-ians, I want to apply a stratified sampling on an image. Following simplified example will explain my problem. The original image I with nrows and ncols is now a vector V of length...
10
by: Johannes Veerkamp | last post by:
hi there, i'm a newbie in c and i'd like to write a programm which generates random numbers from 1 to 10 (integers). can anybody help me out with the correct code? thanx
104
by: fieldfallow | last post by:
Hello all, Is there a function in the standard C library which returns a prime number which is also pseudo-random? Assuming there isn't, as it appears from the docs that I have, is there a...
24
by: pereges | last post by:
I need to generate two uniform random numbers between 0 and 1 in C ? How to do it ? I looked into rand function where you need to #define RAND_MAX as 1 but will this rand function give me ...
26
by: bilgekhan | last post by:
What is the correct method for generating 2 independent random numbers? They will be compared whether they are equal. What about this method: srand(time(0)); int r1 = rand(); srand(rand());...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.