• To: mathgroup at smc.vnet.net
• Date: Thu, 13 Apr 2006 02:19:51 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```On 4/12/06 at 5:59 AM, rjmachado3 at portugalmail.pt (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]

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

In[2]:=x=Sort@Table[Random[Integer,{1,100}],{4}]

Out[2]={40,75,80,92}

(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.,

Out[6]={40,40,75,75,75,75,80,80,80,92}

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

```