Re: Random number with custom distribution
- To: mathgroup at smc.vnet.net
- Subject: [mg107464] Re: Random number with custom distribution
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Sat, 13 Feb 2010 05:23:51 -0500 (EST)
On 2/12/10 at 5:08 AM, giurrero at gmail.com (wiso) wrote: >Dear experts, is there a simple way to generate a random sample of a >custom distribution? With Random I can generate random numbers >according to the predefined distribution (Uniform, Normal, ...) but >what about custom distribution (in my case a polynomial function)? You can generate pseudo random deviates from any distribution you can define in Mathematica. For x selected from any distribution, f, u = CDF[f,x] will have an uniform distribution. So, if you can define the inverse CDF function call it g, g[RandomReal[]] will have the desired distribution. For example, values computed as -Log[RandomReal[]]/a will have the same distribution as values computed as RandomReal[ExponentialDistribution[a]] If the inverse CDF function is not available in closed form or expensive to compute, there are other methods to go from uniform deviates to random deviates from another distribution. Probably the reference to use would be Knuth, Seminumerical Algorithms Vol 2. And if you are going to code your own random generator you really really should read what Knuth has to say about random number generation.