Skip to content

Instantly share code, notes, and snippets.

@HWilliamgo
Last active October 1, 2021 07:12
Show Gist options
  • Save HWilliamgo/0947e760cd859feeb0d55d1f8807ba7f to your computer and use it in GitHub Desktop.
Save HWilliamgo/0947e760cd859feeb0d55d1f8807ba7f to your computer and use it in GitHub Desktop.
[C随机数]#C
/**
* 在[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