Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Re: Generating sequence of 0s and 1s with no repetition

$
0
0
On 7/22/2013 1:32 PM, Vitor wrote:
> Hello.
> I need to generate a sequence of 100 numbers composed of 0s and 1s only.
> But I must guarantee that no more that 3 repetitions occur.
> For xample:
> 1 2 2 1 2 2 1 1 1 2 1... its ok
> 1 2 1 2 2 2 2 1 it's not.
> I used randi for the generation of the sequence. But i'm a bit stuuck
> with the remaining part. I'm sure there is an efficient way of
> achieving this.
> Thanks for any help.

I guess I would alternately sample between {0,00,000} and {1,11,111}
until you get to 100 digits.

Alan Weiss
MATLAB mathematical toolbox documentation

Viewing all articles
Browse latest Browse all 19628

Trending Articles