I am new to Matlab and I'm looking to generate random
numbers with a gaussian distribution in an range of -1 to 1
with a mean of 0. The 'randn' function give me the desired
distribution, but I am unable to determine how to specify
the range. Any help would be greatly appreciated.
Subject: Specific range for a random number generator
"Chris Lee" <mitzoff@hotmail.com> wrote in message
<fd07lt$1rr$1@fred.mathworks.com>...
> I am new to Matlab and I'm looking to generate random
> numbers with a gaussian distribution in an range of -1 to 1
> with a mean of 0. The 'randn' function give me the desired
> distribution, but I am unable to determine how to specify
> the range. Any help would be greatly appreciated.
A Gaussian distribution by definition has a distribution of
(-inf, inf). The standard deviation (sigma) is 1 by default.
If you're looking for a uniform distribution over [-1, 1]
2*rand()-1
~Adam
Subject: Specific range for a random number generator
In article <fd0bpl$8do$1@fred.mathworks.com>,
Adam <not.my.email@mathworks.com> wrote:
>"Chris Lee" <mitzoff@hotmail.com> wrote in message
><fd07lt$1rr$1@fred.mathworks.com>...
>> I am new to Matlab and I'm looking to generate random
>> numbers with a gaussian distribution in an range of -1 to 1
>> with a mean of 0. The 'randn' function give me the desired
>> distribution, but I am unable to determine how to specify
>> the range. Any help would be greatly appreciated.
>A Gaussian distribution by definition has a distribution of
>(-inf, inf).
Right -- so all Chris needs to do is divide the returned value
of randn() by inf in order to scale the results to [-1,1] :)
--
Prototypes are supertypes of their clones. -- maplesoft
Subject: Specific range for a random number generator
On Sep 21, 6:50 am, "Chris Lee" <mitz...@hotmail.com> wrote:
> I am new to Matlab and I'm looking to generate random
> numbers with a gaussian distribution in an range of -1 to 1
> with a mean of 0. The 'randn' function give me the desired
> distribution, but I am unable to determine how to specify
> the range. Any help would be greatly appreciated.
As others have pointed out, a normal (gaussian) distribution
has an infinite range. If you want something with limited
range, you will have to modify the output of randn in
some way.
The most obvious is to throw out samples that don't
fall in your desired range.
You are also going to have to specify what standard
deviation you want. The output of randn has variance
1 so the standard deviation is 1.
- Randy
Subject: Specific range for a random number generator
On Sep 21, 12:34 pm, Randy Poe <poespam-t...@yahoo.com> wrote:
> On Sep 21, 6:50 am, "Chris Lee" <mitz...@hotmail.com> wrote:
>
> > I am new to Matlab and I'm looking to generate random
> > numbers with a gaussian distribution in an range of -1 to 1
> > with a mean of 0. The 'randn' function give me the desired
> > distribution, but I am unable to determine how to specify
> > the range. Any help would be greatly appreciated.
>
> As others have pointed out, a normal (gaussian) distribution
> has an infinite range. If you want something with limited
> range, you will have to modify the output of randn in
> some way.
>
> The most obvious is to throw out samples that don't
> fall in your desired range.
>
> You are also going to have to specify what standard
> deviation you want. The output of randn has variance
> 1 so the standard deviation is 1.
A finite sample might have mean ~ -0.00212 or + 0.00234
and it might have stdv ~ 0.806 or stdv ~ 1.203.
So, if you fiddle around, decide whether you are going
to base the fiddling on the population mean and var (0,1)
or the sample mean and var.
Hope this helps.
Greg
Subject: Specific range for a random number generator
On Sep 23, 12:32 pm, Greg Heath <he...@alumni.brown.edu> wrote:
> On Sep 21, 12:34 pm, Randy Poe <poespam-t...@yahoo.com> wrote:
>
>
>
>
>
> > On Sep 21, 6:50 am, "Chris Lee" <mitz...@hotmail.com> wrote:
>
> > > I am new to Matlab and I'm looking to generate random
> > > numbers with a gaussian distribution in an range of -1 to 1
> > > with a mean of 0. The 'randn' function give me the desired
> > > distribution, but I am unable to determine how to specify
> > > the range. Any help would be greatly appreciated.
>
> > As others have pointed out, a normal (gaussian) distribution
> > has an infinite range. If you want something with limited
> > range, you will have to modify the output of randn in
> > some way.
>
> > The most obvious is to throw out samples that don't
> > fall in your desired range.
>
> > You are also going to have to specify what standard
> > deviation you want. The output of randn has variance
> > 1 so the standard deviation is 1.
>
> A finite sample might have mean ~ -0.00212 or + 0.00234
> and it might have stdv ~ 0.806 or stdv ~ 1.203.
>
> So, if you fiddle around, decide whether you are going
> to base the fiddling on the population mean and var (0,1)
> or the sample mean and var.
>
> Hope this helps.
>
> Greg- Hide quoted text -
>
> - Show quoted text -
Also remember that
1. Although the population mean of a truncated Gaussian distribution
is still 0, the population variance depends on the truncation
threshold.
2. The stats of a finite sample will differ from those of the
population.
Sorry for being so pedantic. However, it is easy to overlook details
when you are feverishly tring to make that deadline.
Greg
Subject: Specific range for a random number generator
"Adam " <not.my.email@mathworks.com> wrote in message
<fd0bpl$8do$1@fred.mathworks.com>...
> "Chris Lee" <mitzoff@hotmail.com> wrote in message
> <fd07lt$1rr$1@fred.mathworks.com>...
> > I am new to Matlab and I'm looking to generate random
> > numbers with a gaussian distribution in an range of -1 to 1
> > with a mean of 0. The 'randn' function give me the desired
> > distribution, but I am unable to determine how to specify
> > the range. Any help would be greatly appreciated.
>
> A Gaussian distribution by definition has a distribution of
> (-inf, inf). The standard deviation (sigma) is 1 by
default.
>
> If you're looking for a uniform distribution over [-1, 1]
> 2*rand()-1
>
> ~Adam
Subject: Specific range for a random number generator
"mahesh kolte" <maheshkolte@mathwoks.com> wrote in message
<feujg2$doa$1@fred.mathworks.com>...
> "Adam " <not.my.email@mathworks.com> wrote in message
> <fd0bpl$8do$1@fred.mathworks.com>...
> > "Chris Lee" <mitzoff@hotmail.com> wrote in message
> > <fd07lt$1rr$1@fred.mathworks.com>...
> > > I am new to Matlab and I'm looking to generate random
> > > numbers with a gaussian distribution in an range of -
1 to 1
> > > with a mean of 0. The 'randn' function give me the
desired
> > > distribution, but I am unable to determine how to
specify
> > > the range. Any help would be greatly appreciated.
> >
> > A Gaussian distribution by definition has a
distribution of
> > (-inf, inf). The standard deviation (sigma) is 1 by
> default.
> >
> > If you're looking for a uniform distribution over [-1,
1]
> > 2*rand()-1
> >
> > ~Adam
>
Hi, how to set the output N? lets say from 1K, increase to
1M. Thanks
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.