Last active
January 4, 2016 05:59
-
-
Save oliverbooth/8578832 to your computer and use it in GitHub Desktop.
Ranged random numbers
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
| #include <stdlib.h> | |
| #include <time.h> | |
| void initrand() { | |
| srand((unsigned) time(NULL)); | |
| rand(); | |
| } | |
| int rangerand(int max, int min) { | |
| if(max < min) max = min; | |
| if(min > max) min = max; | |
| return rand() % max + min; | |
| } |
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
| #ifndef RANGERAND_H | |
| #define RANGERAND_H | |
| void initrand(); | |
| int rangerand(int max, int min = 0); | |
| #endif // !RANGERAND_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment