Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
COde help

Subject: COde help

From: Gauthaman parthiban

Date: 23 Apr, 2009 09:43:01

Message: 1 of 3

Hi,
I want to generate random binary numbers in such a way that
the sum of every 4th number is 1 ........like shown below
0 0 1 0 0 0 0 1 1 0 0 0 and so on continuously........

like 0 0 1 0 0 0 0 1 1 0 0 0 ........for 100 numbers
could it be done........


i have tried with randint........

Subject: COde help

From: tpl@eng.cam.ac.uk (Tim Love)

Date: 23 Apr, 2009 09:55:37

Message: 2 of 3

"Gauthaman parthiban" <gauthaman.p@gmail.com> writes:

>Hi,
>I want to generate random binary numbers in such a way that
>the sum of every 4th number is 1 ........like shown below
>0 0 1 0 0 0 0 1 1 0 0 0 and so on continuously........

>like 0 0 1 0 0 0 0 1 1 0 0 0 ........for 100 numbers
>could it be done........

I'm not certain what you want, but the following idea might help

a=[1 0 0 0 ]
a(randperm(4))

Subject: COde help

From: Roger Stafford

Date: 23 Apr, 2009 15:43:02

Message: 3 of 3

"Gauthaman parthiban" <gauthaman.p@gmail.com> wrote in message <gspd75$4cf$1@fred.mathworks.com>...
> I want to generate random binary numbers in such a way that
> the sum of every 4th number is 1 ........like shown below
> 0 0 1 0 0 0 0 1 1 0 0 0 and so on continuously........
>
> like 0 0 1 0 0 0 0 1 1 0 0 0 ........for 100 numbers
> could it be done........

 p = ceil(4*rand(1,25))+(0:4:96);
 a = zeros(1,100);
 a(p) = 1;

Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us