Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: A conditional random number generation problem (please help me!)

  • To: mathgroup at
  • Subject: [mg65675] Re: A conditional random number generation problem (please help me!)
  • From: Bill Rowe <readnewsciv at>
  • Date: Thu, 13 Apr 2006 02:19:51 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

On 4/12/06 at 5:59 AM, rjmachado3 at (rjmachado3) wrote:

>I need to know the formula for the random function that return
>random numbers in a range of a and b integers [a,b] but that obey on
>a custom probability (possibly different!) for each integer number
>on this [a,b] range (of course the sum of all integer number
>probabilities are = 1!). Finally, what i want is the general
>function formula that simulate the random behavior (based on a
>custom probability value for each integer number between the [a,b]
>range. confuse? i hope not! please help me!!!!

Actually, your description of what you want to accomplish isn't very clear. It sounds to me like you have a finite vector of fixed values each with a different probability of happening and want to generate random values with the same probability distribution. If so, there are a number of ways to solve this problem. For example, start with a set of values



(which can be anything, I've used integers simply for illustration) and a set of relative frequencies

p = {2, 4, 3, 1};

These can be combined to create a "minimum" data set with exactly those relative frequencies, i.e.,



With this

data[[Random[Integer, {1,10}]]]

will give you a result with one of the predefined and the predefined probability distribution.

Another way to do the same thing would be construct an interpolating function for the inverse cumulative distribution function with the InterpolationOrder set to 0. Then f@Random[] where f is the interpolating function will do what you want.

Of these two methods, the first likely requires more memory unless the set of predefined values is reasonably small and the relative frequencies don't sum to a very large number. Assuming this method doesn't have unrealistic memory requirements for your particular case, it should be reasonably fast. Also, since this uses a random integer, Mathematica uses the Wolfram Rule 30 generator which meets all statistical testing I am aware of for randomness.

For larger data sets and particularly when the relative frequencies cannot be easily reduced to small integers, the first method isn't very viable. With the second approach Mathematica uses a subtract with borrow generator that passes most statistical testing but not all. It should be good enough for most applications but may require tweaking for some.

Finally, it is very possible I've misunderstood what you want to achieve. If so, an example of what you want would make it much clearer.
To reply via email subtract one hundred and four

  • Prev by Date: Re: A conditional random number generation problem (please help me!)
  • Next by Date: bug in Partition?
  • Previous by thread: Re: A conditional random number generation problem (please help me!)
  • Next by thread: Re: A conditional random number generation problem (please help me!)