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 number genraration

Subject: random number genraration

From: aralimaradsir@gmail.com

Date: 21 Apr, 2009 06:09:59

Message: 1 of 3

Hi i want to generate a fraction value in between 0.197 to 1. i tried
to use rand and radn functions but i am not geeting the required
valaues.so can anyone help me in this ragard.thank you

Subject: random number genraration

From: Gavrilo Bozovic

Date: 21 Apr, 2009 06:22:03

Message: 2 of 3

aralimaradsir@gmail.com wrote in message <f29c5150-275a-4c35-aff2-c76dff3f1010@x29g2000prf.googlegroups.com>...
> Hi i want to generate a fraction value in between 0.197 to 1. i tried
> to use rand and radn functions but i am not geeting the required
> valaues.so can anyone help me in this ragard.thank you

rand generates uniformly distributed random numbers between 0 and 1. If you get rid of the numbers below 0.197, you'll get uniformly distributed numbers between 0.197 and 1...

like:
your_random_numbers = rand(n_samples,1);
your_random_numbers(your_random_numbers<0.197) = [];

Subject: random number genraration

From: Roger Stafford

Date: 21 Apr, 2009 06:46:03

Message: 3 of 3

"Gavrilo Bozovic" <gavrilo.dot.bozovic@gmail.dot.ch> wrote in message <gsjomb$o2r$1@fred.mathworks.com>...
> aralimaradsir@gmail.com wrote in message <f29c5150-275a-4c35-aff2-c76dff3f1010@x29g2000prf.googlegroups.com>...
> > Hi i want to generate a fraction value in between 0.197 to 1.
>
> rand generates uniformly distributed random numbers between 0 and 1. If you get rid of the numbers below 0.197, you'll get uniformly distributed numbers between 0.197 and 1...

  It is not necessary to reject any random values. Just use the appropriate linear combination on 'rand' values:

 a = 0.197; % Lower bound
 b = 1; % Upper bound
 r = (b-a)*rand(n,1)+a;

These will be uniformly distributed between a and b.

Roger Stafford

Tags for this Thread

No tags are associated with 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