Generate pseudo-random sequence of 1 and 0 so that each pairing in the sequence appears and equal number of times

40 Views Asked by At

Edit: As pointed out by VTand below, this is indeed not possible due to the number of pairs with 32 elements, but I'm curious about any solutions for different list lengths too.

I need to generate a pseudo-random list of a given length, consisting of and equal number of 0s and 1s. Each pairing in the sequence needs to appear an equal number of times, so there needs to be an equal number of:

  • 0s followed by 0s
  • 0s followed by 1s
  • 1s followed by 0s
  • 1s followed by 1s

I have two problems:

  1. I am not sure how many of these there are even, could this be too big of a constraint?
  2. Not sure what the best way of generating these would be even if theoretically possible. I could start with a 0 or 1 and then try to assign a value to increase the number of occurrences for the currently least frequently occurring sequence (or chose randomly if there are multiple). I feel like this will probably not cover the whole range of possibilities though.

Does anyone have any better ideas to get started on this?

1

There are 1 best solutions below

0
On

Ok, thinking about this based on VTand's commend, I am pretty sure this will not be possible.

To satisfy the ordering requirement, we need to have a number of pairings that is divisible by 4. This means that the number of pairings is even. However, that means that our list length odd, which makes satisfying the requirement for equal number of 1s and 0s impossible.