จำนวนสุ่ม

Python ระดับกลาง

Hugo Bowne-Anderson

Data Scientist at DataCamp

Python ระดับกลาง

Python ระดับกลาง

Python ระดับกลาง

Python ระดับกลาง

Python ระดับกลาง

  • ลงต่ำกว่าขั้น 0 ไม่ได้
  • โอกาส 0.1% ที่จะพลัดตกบันได
  • เดิมพัน: จะขึ้นถึงขั้นที่ 60
Python ระดับกลาง

จะแก้ปัญหาอย่างไร?

  • เชิงวิเคราะห์
  • จำลองกระบวนการ
    • Hacker statistics!
Python ระดับกลาง

ตัวสร้างจำนวนสุ่ม

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 ระดับกลาง

ตัวสร้างจำนวนสุ่ม

np.random.seed(123)
np.random.rand()
0.696469185597861    # Same seed: same random numbers!
np.random.rand()     # Ensures "reproducibility"
0.28613933495037946
Python ระดับกลาง

โยนเหรียญ

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 ระดับกลาง

โยนเหรียญ

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 ระดับกลาง

มาฝึกกันเถอะ!

Python ระดับกลาง

Preparing Video For Download...