Created
July 9, 2016 10:21
-
-
Save vladdeSV/d41e974df03f2fc56650895ca2a887bc 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
/** | |
* Simple random checking. | |
*/ | |
module slump; | |
import std.random : uniform; | |
///Returns: One out of `oneOutOf´ probability's chance of returning true | |
bool probabilityOf(int oneOutOf) | |
{ | |
return uniform(0, oneOutOf) == 0; | |
} | |
///Returns: random number within 0 and `count` | |
int random(int count) | |
{ | |
return uniform(0, count); | |
} | |
///Returns: random element in array | |
A random(A)(A[] arr) | |
{ | |
return arr[random($)]; | |
} | |
///Returns: randomly true or false | |
bool coin() | |
{ | |
return cast(bool) uniform(0, 2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment