Variance of uniform distribution: var(x)=E[X? ]-(E[X])?
var(x)=E[X? ]-(E[X])? = 1/3(a? +ab+ b? )- 1/4(a+b)? = 1/ 12(a? -2ab+ b? )= 1/ 12(a-b)?
If x obeys uniform distribution on [2,4], then the mathematical expectation ex = (2+4)/2 = 3; Variance DX=(4-2)? / 12= 1/3。
Sampling from an arbitrary distribution
Uniform distribution is suitable for sampling with arbitrary distribution. The general method is the inverse transformation sampling method using the cumulative distribution function (CDF) of the target random variable. This method is very useful in theoretical work. Because the simulation using this method needs to invert the cdf of the target variable, an alternative method is designed for the case that the closed form of CDF is unknown. One way is to refuse sampling.
Normal distribution is an important example of the inefficiency of inverse transformation method. But there is an exact method, Box-Muller transformation, which transforms two independent uniform random variables into two independent normal distribution random variables by inverse transformation.