Numéros 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

  • Il n'est pas possible de descendre en dessous de la marche 0
  • 0,1 % de probabilité de tomber dans les escaliers
  • Pari : vous atteindrez la 60ème marche
Python intermédiaire

Comment résoudre ce problème ?

  • Analytique
  • Simuler le processus
    • Statistiques façon hacker !
Python intermédiaire

Générateurs aléatoires

import numpy as np
np.random.rand()      # Pseudo-random numbers
0.9535543896720104    # Mathematical formula
np.random.seed(123)    # Starting from a seed
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    # Same seed: same random numbers!
np.random.rand()     # Ensures "reproducibility"
0.28613933495037946
Python intermédiaire

Tirage au sort

game.py

import numpy as np

np.random.seed(123)
coin = np.random.randint(0,2) # Randomly generate 0 or 1
print(coin)
0
Python intermédiaire

Tirage au sort

game.py

import numpy as np
np.random.seed(123)
coin = np.random.randint(0,2)  # Randomly generate 0 or 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...