2
$\begingroup$

There are a lot of questions about generating random numbers form both uni-variate and bi-variate distributions. Mathematica has a lot of built in distributions for that purpose. However, I could not do what I wanted to do. I am looking for help.

I want to generate random numbers using built in Mathematica distribution but would like to put some restriction. For example, the following code gives me 2000 random numbers form exponential distribution.

example1=RandomVariate[ExponentialDistribution[0.0067], 2000];

However, I am trying to get 2000 random variables greater than say 20 from exponential distribution. Similarly, the following code gives me 2000 random numbers a form Farlie-Gumbel-Morgenstern copula.

   example2=RandomVariate[
     CopulaDistribution[{"FGM", .34}, {NormalDistribution[0, 1], 
       ExponentialDistribution[0.0067]}], 2000];

However, I want to get 2000 random numbers form Normal distribution between -.02 and .02 or I want random numbers form exponential distribution between 40 and 1000.

Any help is greatly appreciated. Thank you in advance.

$\endgroup$
2
  • 3
    $\begingroup$ TruncatedDistribution may be what you are after. $\endgroup$
    – Andy Ross
    Commented Dec 18, 2014 at 1:28
  • $\begingroup$ @ Andy, you are right. But I am also expecting some innovative answers, which I always get form this community. $\endgroup$
    – ramesh
    Commented Dec 18, 2014 at 2:19

1 Answer 1

8
$\begingroup$
d1 = RandomVariate[ExponentialDistribution[.1], 2000];
d2 = RandomVariate[TruncatedDistribution[{20, 40}, ExponentialDistribution[.1]], 2000];

GraphicsColumn[{Histogram[d1, {1}, PlotRange -> {{0, 72}, {0, 250}}],
                Histogram[d2, {1}, PlotRange -> {{0, 72}, {0, 250}}, AxesOrigin -> {0, 0}]}]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ @ belisarius thank you for taking time to answer my question. This proves that I am a new user of Mathematica. However, I am expecting some more answers so I can play with. Thanks again. $\endgroup$
    – ramesh
    Commented Dec 18, 2014 at 2:17
  • $\begingroup$ @rka Feeling comfortable with mathematica takes some time. Be patient and keep trying $\endgroup$ Commented Dec 18, 2014 at 2:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.