### Tags: 1with, distribution, gaussian, generate, generator, matlab, number, programming, random, randomnumbers, range, specific

# Specific range for a random number generator

On Programmer » Matlab

4,930 words with 6 Comments; publish: Mon, 28 Apr 2008 05:43:00 GMT; (20093.75, « »)

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.

*http://matlab.todaysummary.com/q_matlab_56747.html*

All Comments

Leave a comment...

- 6 Comments
- "Chris Lee" <mitzoff.matlab.todaysummary.com.hotmail.com> wrote in message
<fd07lt$1rr$1.matlab.todaysummary.com.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

#1; Mon, 28 Apr 2008 05:44:00 GMT

- "Chris Lee" <mitzoff.matlab.todaysummary.com.hotmail.com> wrote in message
- In article <fd0bpl$8do$1.matlab.todaysummary.com.fred.mathworks.com>,
Adam <not.my.email.matlab.todaysummary.com.mathworks.com> wrote:

>"Chris Lee" <mitzoff.matlab.todaysummary.com.hotmail.com> wrote in message

><fd07lt$1rr$1.matlab.todaysummary.com.fred.mathworks.com>...

>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

#2; Mon, 28 Apr 2008 05:45:00 GMT

- In article <fd0bpl$8do$1.matlab.todaysummary.com.fred.mathworks.com>,
- On Sep 21, 6:50 am, "Chris Lee" <mitz....matlab.todaysummary.com.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

#3; Mon, 28 Apr 2008 05:46:00 GMT

- On Sep 21, 6:50 am, "Chris Lee" <mitz....matlab.todaysummary.com.hotmail.com> wrote:
- On Sep 21, 12:34 pm, Randy Poe <poespam-t....matlab.todaysummary.com.yahoo.com> wrote:
> On Sep 21, 6:50 am, "Chris Lee" <mitz....matlab.todaysummary.com.hotmail.com> wrote:

>

> 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

#4; Mon, 28 Apr 2008 05:47:00 GMT

- On Sep 21, 12:34 pm, Randy Poe <poespam-t....matlab.todaysummary.com.yahoo.com> wrote:
- On Sep 23, 12:32 pm, Greg Heath <he....matlab.todaysummary.com.alumni.brown.edu> wrote:
> On Sep 21, 12:34 pm, Randy Poe <poespam-t....matlab.todaysummary.com.yahoo.com> wrote:

>

>

>

>

>

>

>

> 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

#5; Mon, 28 Apr 2008 05:49:00 GMT

- On Sep 23, 12:32 pm, Greg Heath <he....matlab.todaysummary.com.alumni.brown.edu> wrote:
- "Adam " <not.my.email.matlab.todaysummary.com.mathworks.com> wrote in message
<fd0bpl$8do$1.matlab.todaysummary.com.fred.mathworks.com>...

> "Chris Lee" <mitzoff.matlab.todaysummary.com.hotmail.com> wrote in message

> <fd07lt$1rr$1.matlab.todaysummary.com.fred.mathworks.com>...

> 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

#6; Mon, 28 Apr 2008 05:49:00 GMT

- "Adam " <not.my.email.matlab.todaysummary.com.mathworks.com> wrote in message