Last active
November 19, 2017 17:53
-
-
Save PiotrZakrzewski/131c4f3bb47d6fc3369ad9f302c24eec to your computer and use it in GitHub Desktop.
Random drop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import random | |
ILOSC_KREGOW = 9 | |
probabilities = np.array([np.exp(-x) for x in range(ILOSC_KREGOW) ]) | |
normalized_probs = probabilities / np.sum(probabilities) # teraz ich suma to 1.0 | |
print("Prawdopodobienswa po normalizacji", normalized_probs) | |
normalized_probs = list(normalized_probs) | |
def get_random_kreg(): | |
r = random.random() | |
print("Wylosowana liczba:", r) | |
previous = 0 | |
for kreg, prob in enumerate(normalized_probs): | |
prob += previous | |
previous = prob | |
if r < prob: | |
return kreg | |
return ILOSC_KREGOW # ponizej najmniejszego prawdopodobienstwa | |
print("Wybrany krag:", get_random_kreg()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment