Số ngẫu nhiên

Python nâng cao

Hugo Bowne-Anderson

Data Scientist at DataCamp

Python nâng cao

Python nâng cao

Python nâng cao

Python nâng cao

Python nâng cao

  • Không thể xuống dưới bậc 0
  • Xác suất 0,1% bị ngã cầu thang
  • Cá cược: bạn sẽ lên bậc 60
Python nâng cao

Giải thế nào?

  • Phân tích
  • Mô phỏng quá trình
    • Hacker statistics!
Python nâng cao

Bộ sinh số ngẫu nhiên

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 nâng cao

Bộ sinh số ngẫu nhiên

np.random.seed(123)
np.random.rand()
0.696469185597861    # Same seed: same random numbers!
np.random.rand()     # Ensures "reproducibility"
0.28613933495037946
Python nâng cao

Tung đồng xu

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 nâng cao

Tung đồng xu

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 nâng cao

Ayo berlatih!

Python nâng cao

Preparing Video For Download...