Last active
October 1, 2021 07:12
-
-
Save HWilliamgo/0947e760cd859feeb0d55d1f8807ba7f to your computer and use it in GitHub Desktop.
[C随机数]#C
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
/** | |
* 在[range]范围内生成一个正的随机数 | |
* @param range 范围 | |
* @return 随机数 | |
*/ | |
static int randomNum(int range) { | |
// 用当前时间戳生成随机数种子 | |
time_t seed = time(0); | |
// 将随机数种子填写到随机数生成器里面 | |
srand(seed); | |
// 生成随机数并取模 | |
return rand() % range; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment