<> uniform distribution U(a,b) Mean and variance

·

<> verification U(a,b) What's the average value of (a+b)/2
""" 2020/2/23 verification U(a,b) Is that the mean value of (a+b)/2 """ from random import uniform n = int(
input('please enter the number of test: ')) # Number of tests ( The more, the more true ) a = float(input(
'please enter the lower bond:: ')) b = float(input('please enter the upper
bond:: ')) sums = 0 for i in range(n): sums += uniform(a,b) print(' The average is '+str(
'%.2f'%(sums/n))) print('(a+b)/2 The value of is :%.2f'%((a+b)/2))
The results show that the mean value of the number obtained by uniform distribution random value tends to be close to the average value (a+b)/2
please enter the number of test: 10000 please enter the lower bond: 2 please
enter the upper bond: 10 The average is 5.99(a+b)/2 The value of is :6.00
<> verification U(a,b) What's the variance (a-b)**2/12

Variance calculation method :

""" 2020/2/27 verification U(a,b) Is the variance of (a-b)**2/12 """ from random import uniform n = int(
input('please enter the number of test: ')) a = float(input('please enter the
lower bond: ')) b = float(input('please enter the lower bond: ')) sums = 0 for i
in range(n): sums += (uniform(a,b)-(a+b)/2)**2 print(' The variance is '+str('%.2f'%(sums/n)))
print('(a-b)**2/12 The value of is :%.2f'%(((a-b)**2)/12)) please enter the number of test:
10000 please enter the lower bond: 2 please enter the lower bond: 20 The variance is 27.17(
a-b)**2/12 The value of is :27.00

Technology