# Beta Distributions

- Author:
- Michael Horvath

- Topic:
- Probability

*(Note: You can manipulate the shape of the curve in the above graph by dragging the handles of the "ParamA" and "ParamB" sliders.)*Beta distributions are a great way to create smooth random distributions with known limits. Beta distributions are limited to the range of 0 to 1 along the x axis, and in their normal form are also limited in such a way that the area beneath the graph is always equal to 1, or "unity". Beta distributions are controlled by two parameters, A and B (or alpha and beta), that determine the shape of the curve. When A and B are equal and greater than 1, the distribution has a nice bell shape. When one or the other parameters is greater, then the shape is "lop-sided" toward either the left or right side. When either parameter is less than 1, the shape of the curve becomes concave instead of convex. The first part of the formula for a beta distribution is:

`f(x) = x^(A - 1) (1 - x)^(B - 1)`

You then divide f(x) by the integral between 0 and 1 of the same function to get g(x):
`g(x) = f(x) / integral(f(x), 0, 1)`

If, instead, you want to normalize the curve by its height instead of its area, the formula is a bit simpler. In this case you do not need to divide f(x) by its integral. Rather, you just divide it by the height of the curve at its highest point (the "vertex").
To calculate the curve's vertex, you first need to determine the x value using the following formula:

`x_vertex = (A - 1) / (A - 1 + B - 1)`

Then, simply plug this x value into f(x) to get the corresponding y value. Finally, compute the following:
`g(x) = f(x) / y_vertex`

To generate a random number that fits this distribution, simply plug a random value between 0 and 1 into g(x).