Created
February 9, 2016 07:30
-
-
Save riceluxs1t/a9790254470aeb3d6874 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
func throw_dice (arr_weights) { | |
W <- sum(arr_weights) | |
T <- RANDOM(0, W) // sample uniformly from [0, W) | |
cumsum <- 0 | |
FOR i in 0..n-1, DO { | |
IF T-cumsum <= arr_weigths[i], THEN | |
RETURN arr_weights[i] | |
cumsum += arr_weights[i] | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment