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:
random sequences with myrandint - simple question

Subject: random sequences with myrandint - simple question

From: Yannos M

Date: 8 Mar, 2012 16:20:17

Message: 1 of 4

Hello,

I'm using myrandint as found in:
http://www.mathworks.co.uk/matlabcentral/fileexchange/5346-myrandint-random-integer-generation

to generate a [1,11] size matrix of random numbers in a range -1:0.1:1.
The question is how can I exclude zero from this random selection?

thank you!

Subject: random sequences with myrandint - simple question

From: Roger Stafford

Date: 8 Mar, 2012 19:33:37

Message: 2 of 4

"Yannos M" wrote in message <jjam81$b0t$1@newscl01ah.mathworks.com>...
> ......
> to generate a [1,11] size matrix of random numbers in a range -1:0.1:1.
> The question is how can I exclude zero from this random selection?
> ......
- - - - - - - -
 x = [-1:0.1:-0.1,0.1:0.1:1];
 y = x(ceil(20*rand(1,11)));

Roger Stafford

Subject: random sequences with myrandint - simple question

From: Yannos M

Date: 9 Mar, 2012 11:44:10

Message: 3 of 4

Roger,
Although I'm not so sure if this is random or pseudo-random thanks a lot!


"Roger Stafford" wrote in message <jjb1ih$lbi$1@newscl01ah.mathworks.com>...
> "Yannos M" wrote in message <jjam81$b0t$1@newscl01ah.mathworks.com>...
> > ......
> > to generate a [1,11] size matrix of random numbers in a range -1:0.1:1.
> > The question is how can I exclude zero from this random selection?
> > ......
> - - - - - - - -
> x = [-1:0.1:-0.1,0.1:0.1:1];
> y = x(ceil(20*rand(1,11)));
>
> Roger Stafford

Subject: random sequences with myrandint - simple question

From: Roger Stafford

Date: 9 Mar, 2012 20:42:17

Message: 4 of 4

"Yannos M" wrote in message <jjcqea$bnn$1@newscl01ah.mathworks.com>...
> Although I'm not so sure if this is random or pseudo-random thanks a lot!
> .......
- - - - - - - - - -
  It is necessarily pseudo-random, as is everything else matlab code can provide without access to the external world, but it is the best that matlab can do on a deterministic machine.

  If you run it a great many times you should see a nearly uniform distribution within -1:0.1:1 except for 0.0 which should never occur. That is all you can ask of such code.

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