loi uniforme
Python
import numpy as np
import numpy.random as rd
import matplotlib.pyplot as plt
import time
def uniforme(n,m,nb_sim):
plt.close()
rd.random(10)
#loi empirique
X=np.zeros(m-n+1)
start=time.time()
for _ in range (nb_sim):
sim=rd.randint(m-n+1)
X[sim]+=1
end=time.time()
duree=str("{:.2f}".format(1000*(end-start)))+"ms"
print(X ,"nombre d'apparition de l'entier lors des simulations")
#loi théorique
Y=np.zeros(m-n+1)
for k in range (m-n+1): #attention que ce soit bien de là qu'on commence
Y[k]=1/(m-n+1)
y=np.arange(m+1)
plt.hist([X/(m-n+1),Y], y, rwidth=0.8, align="left", density="True",label=["empirique","théorique"])
#est-ce que pas mieux de faire un plot pour Y
plt.title("rd.randint, t=" + duree)
plt.legend()
plt.show()
uniforme(0,10,1000)
Output
Embed on website
To embed this program on your website, copy the following code and paste it into your website's HTML:
Comments
This comment belongs to a banned user and is only visible to admins.
This comment belongs to a deleted user and is only visible to admins.