MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Random number generation( b/w two limits) with a

  • To: mathgroup at smc.vnet.net
  • Subject: [mg109798] Re: Random number generation( b/w two limits) with a
  • From: Barrie Stokes <Barrie.Stokes at newcastle.edu.au>
  • Date: Tue, 18 May 2010 02:02:05 -0400 (EDT)

Hi

In contrast to some of the answers you've already received, I thought you might be looking for random numbers that have a truncated Gaussian distribution.
I'm taking your term "comply" to mean the distribution does conform to a Gaussian PDF (Probability Density Function), but only between given limits.
I would be interested to hear about the context of your question; you might be asking, and I might be answering, the wrong question. :-)
I had need of something similar for the multivariate Gaussian just earlier this week - this was the essence of my approach:

ClearAll[  restrictedGaussian ]
restrictedGaussian[  mean_, sd_ , low_, hi_ ] := Module[  {n, rn},
 n = 1;
 While[  True,
(
rn = RandomReal[ NormalDistribution[ mean, sd ] ];
If[ low < rn < hi, Break[  ] ]
);
n++ ];
rn ]

restrictedGaussian[ 1, 1 , -3, 3 ]

restrictedSample = Table[ restrictedGaussian[ 2, 1 , -3, 3 ], {10000} ];
% // Short
Histogram[ restrictedSample ]

restrictedSample = Table[ restrictedGaussian[ 0, 2 , -4, 4 ], {10000} ];
% // Short
Histogram[ restrictedSample ]

Your question perhaps:

restrictedSample = Table[ restrictedGaussian[ 0, 1 , -4, 4 ], {10000} ];
% // Short
Histogram[ restrictedSample ]

Hope this could someday be useful.

Barrie

>>> On 16/05/2010 at 7:57 pm, in message <201005160957.FAA03713 at smc.vnet.net>,
"elvisgraceland at gmail.com" <elvisgraceland at gmail.com> wrote:
> Dear experts,
> Is it possible to generate random numbers b/w any two limits (say b/w
> -4 & 4 ) which would comply to a gaussian distribution ?



  • Prev by Date: Re: Remove points from InterpolatingFunction
  • Next by Date: Re: Overloading StringJoin
  • Previous by thread: Re: Multiple FindRoot
  • Next by thread: Washington DC Area Mathematica SIG