# -*- coding: utf-8 -*-
"""
Created on Sun Jul 10 17:59:27 2022

@author: starons

"""
"""
Brève illustration des possibilités offertes par le module random de numpy
"""

# On importe les bibliothèques utiles
# -----------------------------------
import numpy as np
from matplotlib import pyplot as plt
from numpy import random

# On joue aux dés
# ---------------
N = 25
tirage = random.randint(1,7,N)
print("On joue aux dés :",tirage)

# Loi uniforme
# ------------
a,b = 3,7
N = 5000
X = random.uniform(a,b,N)
plt.subplot(1,2,1)
plt.xlabel("X")
plt.ylabel("Fréquence")
plt.hist(X,bins='rice',color='white',edgecolor='black')
plt.title("Loi uniforme")
print("Loi uniforme")
print("moyenne : {:.3f}  écart-type : {:.3f}".format(np.mean(X),np.std(X,ddof=1)))
 
# Loi normale
# -----------
mu,sigma = 10,2.5
N = 5000
Y = random.normal(mu,sigma,N)
plt.subplot(1,2,2)
plt.xlabel("Y")
plt.ylabel("Fréquence")
plt.hist(Y,bins='rice',color='white',edgecolor='black')
plt.title("Loi normale")
print("Loi normale")
print("moyenne : {:.3f}  écart-type : {:.3f}".format(np.mean(Y),np.std(Y,ddof=1)))