Nombres aléatoires

Python intermédiaire

Hugo Bowne-Anderson

Data Scientist at DataCamp

Python intermédiaire

Python intermédiaire

Python intermédiaire

Python intermédiaire

Python intermédiaire

  • Impossible de descendre sous la marche 0
  • 0,1 % de risque de tomber dans l'escalier
  • Pari : atteindre la marche 60
Python intermédiaire

Comment résoudre ?

  • Analytique
  • Simuler le processus
    • Hacker statistics !
Python intermédiaire

Générateurs aléatoires

import numpy as np
np.random.rand()      # Nombres pseudoaléatoires
0.9535543896720104    # Formule mathématique
np.random.seed(123)    # Démarrer avec une graine
np.random.rand()
0.6964691855978616
np.random.rand()
0.28613933495037946
Python intermédiaire

Générateurs aléatoires

np.random.seed(123)
np.random.rand()
0.696469185597861    # Même graine : mêmes nombres aléatoires !
np.random.rand()     # Assure la « reproductibilité »
0.28613933495037946
Python intermédiaire

Pile ou face

game.py

import numpy as np

np.random.seed(123)
coin = np.random.randint(0,2) # Génère aléatoirement 0 ou 1
print(coin)
0
Python intermédiaire

Pile ou face

game.py

import numpy as np
np.random.seed(123)
coin = np.random.randint(0,2)  # Génère aléatoirement 0 ou 1
print(coin)

if coin == 0: print("heads")
else: print("tails")
0
heads
Python intermédiaire

Passons à la pratique !

Python intermédiaire

Preparing Video For Download...