Last active
August 29, 2015 14:23
-
-
Save games/5967b2a96a6b093aa001 to your computer and use it in GitHub Desktop.
pick some one from list by weight
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
| let pick items weight = | |
| let rec pick based = | |
| function | |
| | [] -> None | |
| | (w, _) as h :: _ when weight <= w + based -> Some h | |
| | (w, _) :: t -> pick (based + w) t | |
| pick 0.0 items |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment