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 generation

Subject: random number generation

From: ammal

Date: 18 Mar, 2008 19:27:01

Message: 1 of 7

Hellow everybody,

I need a hand on how to generate a 100 positive numbers
that follow a normal distribution curve (Bell Shape).In
otherwords, if i histogram the data, a bell shape will be
generated. i am not transforming my data, instead, i want
to generate a posirtive one hundred values that will follow
a bell shape.

Thanks,
Ammal

Subject: random number generation

From: Randy Poe

Date: 18 Mar, 2008 19:34:08

Message: 2 of 7

On Mar 18, 3:27 pm, "AMMAL " <alan...@ualberta.ca> wrote:
> Hellow everybody,
>
> I need a hand on how to generate a 100 positive numbers
> that follow a normal distribution curve (Bell Shape).In
> otherwords, if i histogram the data, a bell shape will be
> generated. i am not transforming my data, instead, i want
> to generate a posirtive one hundred values that will follow
> a bell shape.
>
> Thanks,
> Ammal

The function RANDN will generate samples from a
standard normal distribution. Note that if you histogram
the results, you won't get a perfect bell shape since samples,
being random, have a little variation in them. The mean
of your samples won't be exactly 0, but something close.
The variance won't be exactly 1, but something close.

That's the nature of random variables and samples.

                 - Randy

Subject: random number generation

From: Roger Stafford

Date: 18 Mar, 2008 19:42:01

Message: 3 of 7

"AMMAL " <alanazi@ualberta.ca> wrote in message <frp525$8i
$1@fred.mathworks.com>...
> Hellow everybody,
>
> I need a hand on how to generate a 100 positive numbers
> that follow a normal distribution curve (Bell Shape).In
> otherwords, if i histogram the data, a bell shape will be
> generated. i am not transforming my data, instead, i want
> to generate a posirtive one hundred values that will follow
> a bell shape.
>
> Thanks,
> Ammal
------
  You can use "s*randn(1,100)+m" to generate a hundred normal distribution
numbers with mean m and standard deviation s, but you cannot be sure all of
them will be positive. You cannot have a normal distribution and at the same
time have only positive numbers. That is a contradiction in terms. The "bell
shape" extends all the way to minus and plus infinity.

Roger Stafford

Subject: random number generation

From: richardstartz@comcast.net

Date: 18 Mar, 2008 19:46:06

Message: 4 of 7

On Tue, 18 Mar 2008 19:42:01 +0000 (UTC), "Roger Stafford"
<ellieandrogerxyzzy@mindspring.com.invalid> wrote:

>"AMMAL " <alanazi@ualberta.ca> wrote in message <frp525$8i
>$1@fred.mathworks.com>...
>> Hellow everybody,
>>
>> I need a hand on how to generate a 100 positive numbers
>> that follow a normal distribution curve (Bell Shape).In
>> otherwords, if i histogram the data, a bell shape will be
>> generated. i am not transforming my data, instead, i want
>> to generate a posirtive one hundred values that will follow
>> a bell shape.
>>
>> Thanks,
>> Ammal
>------
> You can use "s*randn(1,100)+m" to generate a hundred normal distribution
>numbers with mean m and standard deviation s, but you cannot be sure all of
>them will be positive. You cannot have a normal distribution and at the same
>time have only positive numbers. That is a contradiction in terms. The "bell
>shape" extends all the way to minus and plus infinity.
>
>Roger Stafford

Roger's advice is correct of course.
Having said that, you can insure that a *sample*is entirely positive.
For example:
x = s*randn(1,100)+m;
if min(x)<0
 x = x + abs(min(x));
end

-Dick Startz

Subject: random number generation

From: ammal

Date: 18 Mar, 2008 20:17:01

Message: 5 of 7

Thank you all for your answer,
I am wondering now how i would include the codition
statement you wrote in the block code to ensure the samples
are positive.Could you please show me how to include it in
a for loop maybe.

Thanks,
Ammal

richardstartz@comcast.net wrote in message
<8r60u3p6eauu99plunl4oo31dd1o242jq2@4ax.com>...
> On Tue, 18 Mar 2008 19:42:01 +0000 (UTC), "Roger Stafford"
> <ellieandrogerxyzzy@mindspring.com.invalid> wrote:
>
> >"AMMAL " <alanazi@ualberta.ca> wrote in message <frp525
$8i
> >$1@fred.mathworks.com>...
> >> Hellow everybody,
> >>
> >> I need a hand on how to generate a 100 positive
numbers
> >> that follow a normal distribution curve (Bell
Shape).In
> >> otherwords, if i histogram the data, a bell shape will
be
> >> generated. i am not transforming my data, instead, i
want
> >> to generate a posirtive one hundred values that will
follow
> >> a bell shape.
> >>
> >> Thanks,
> >> Ammal
> >------
> > You can use "s*randn(1,100)+m" to generate a hundred
normal distribution
> >numbers with mean m and standard deviation s, but you
cannot be sure all of
> >them will be positive. You cannot have a normal
distribution and at the same
> >time have only positive numbers. That is a
contradiction in terms. The "bell
> >shape" extends all the way to minus and plus infinity.
> >
> >Roger Stafford
>
> Roger's advice is correct of course.
> Having said that, you can insure that a *sample*is
entirely positive.
> For example:
> x = s*randn(1,100)+m;
> if min(x)<0
> x = x + abs(min(x));
> end
>
> -Dick Startz

Subject: random number generation

From: Vihang Patil

Date: 19 Mar, 2008 08:20:04

Message: 6 of 7

"AMMAL " <alanazi@ualberta.ca> wrote in message <frp525
$8i$1@fred.mathworks.com>...
> Hellow everybody,
>
> I need a hand on how to generate a 100 positive numbers
> that follow a normal distribution curve (Bell Shape).In
> otherwords, if i histogram the data, a bell shape will
be
> generated. i am not transforming my data, instead, i
want
> to generate a posirtive one hundred values that will
follow
> a bell shape.
>
> Thanks,
> Ammal

Hello
I am not sure about the Bell thing, but if you want to
generate 100 random positive numbers then you can use this
n = 100;
f = ceil(n.*rand(100,1));

HTH
Vihang

Subject: random number generation

From: Greg Heath

Date: 19 Mar, 2008 14:01:56

Message: 7 of 7

On Mar 18, 3:46=A0pm, richardsta...@comcast.net wrote:
> On Tue, 18 Mar 2008 19:42:01 +0000 (UTC), "Roger Stafford"
>
>
>
>
>
> <ellieandrogerxy...@mindspring.com.invalid> wrote:
> >"AMMAL " <alan...@ualberta.ca> wrote in message <frp525$8i
> >$...@fred.mathworks.com>...
> >> Hellow everybody,
>
> >> I need a hand on how to generate a 100 positive numbers
> >> that follow a normal distribution curve (Bell Shape).In
> >> otherwords, if i histogram the data, a bell shape will be
> >> generated. i am not transforming my data, instead, i want
> >> to generate a posirtive one hundred values that will follow
> >> a bell shape.
>
> >> Thanks,
> >> Ammal
> >------
> > =A0You can use "s*randn(1,100)+m" to generate a hundred normal distribut=
ion
> >numbers with mean m and standard deviation s, but you cannot be sure all =
of
> >them will be positive. =A0You cannot have a normal distribution and at th=
e same
> >time have only positive numbers. =A0That is a contradiction in terms. =A0=
The "bell
> >shape" extends all the way to minus and plus infinity.
>
> >Roger Stafford
>
> Roger's advice is correct of course.
> Having said that, you can insure that a *sample*is entirely positive.
> For example:
> x =3D s*randn(1,100)+m;
> if min(x)<0
> =A0x =3D x + abs(min(x));
> end

Alternatively, you can reject negative values
and keep generating until you have 100.

In either case, the resulting distribution is ...

ABNORMAL! (;>)

Greg

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