# Continues Random Distribution

## Recommended Posts

arithma    226
THIS IS A MINIARTICLE I WROTE MY SELF TO THE BENEFIT OF OTHERS In many situations we need a weighted algorithm that generates numbers in a given range. The hard thing about it is that you can't create a precise distribution for all the numbers in that interval. I HAVE SOLVED IT Let's say our interval is [0,a] We denote by p(x) the differential probability of x where x <- [0,a] integral of p(x) from 0 to a is by our conditions 1. What we have done thus far is defining the distribution for every number in [0,a]. It doesn't have any meaning but that the probability of a number <- [u,v] is equal to integral of p(x) from u to v as an example we take a = 1, p(x) = 6*(x - x^2) Now we need a function that when we input a number between 0 and 1 it returns a number between 0 and 'a' with the given distribution p(x) THE FUNCTION IS NAMED F(x), its inverse G(x)... Their respective derivatives f(x) and g(x) - DOMAIN = [0,1] - RANGE = [0,a] This functions is required to behave under the following conditions: - IF THE INPUT IS UNIFORMLY DISTRIBUTED OVER THE DOMAIN THEN THE OUTPUT IS DISTRIBUTED OVER THE RANGE BY THE FUNCTION p(x) this is equivalent to saying: for any [u,v] we have: G(v) - G(u) = integrate p(x) from u to v this statement comes from the one before it since any input between G(u) and G(v) into F will return a number between u and v The upper statement can be evolved to the more mature statement (and equivalent) g(u) = p(u) Integrate both sides G(u) = integrate p(x) from 0 to u F(u) = inverse of integral(p(x),x=0 to u) Using the example given: F(x) = inverse of (3*x^2 - 2*x^3) You can develop this equation on your own (i have not taken cubic equations yet, still in high school)

##### Share on other sites
Guest Anonymous Poster
Well, that's quite elementary knowledge. The only problem is that in many cases there doesn't exist an analytical solution to the function F(x), so you will need to find other ways to generate the distribution.

##### Share on other sites
Dmytry    1151
exactly, if i interpreted OP's right, some basic knowledge about calculus applied to statistics.

Idea is simple: look at graph of function f(x) with probability that random value is less than x
Note that y goes from 0 to 1. Note that every y is equally probable. So get random number y between 0 to 1 and compute inverse_of_f(y) to find apporiate x
Also, note that derivative of f is probability distribution, so f is integral of probability distributuon.

If you got that idea yourself, that is very good thing. Keep reinventing the wheel in free time - it's actually quite good for learning. (of course you can't repeat all the science, but it's very good to reinvent everything you can reinvent)

##### Share on other sites
Guest Anonymous Poster
Right here at gamedev:
http://www.gamedev.net/reference/articles/article1337.asp

And no need for the caps.