如题 麻烦帮忙看看咋回事哦

int a=0;
srand((unsigned)time(0));
a=rand()%10;

能出现a==0 吗?
a== 10 能出现吗?

呼唤远方
浏览 116回答 2
2回答

富国沪深

#include <stdlib.h>#include <time.h>int a = 0;srand(time(NULL));a = rand()%10;a可能的随机范围0-9,不会出现10.

有只小跳蛙

不能出现10,但是0是会出现的。想出现10的话改成&nbsp;#include <iostream>#include <cstdlib>//cstdlib文件包含处理生成随机数的函数以及其他函数#include <ctime>//与随机函数同时使用using namespace std;int main(){srand(time(0));//根据当前时间生成随机数生成器种子int randomNumber = rand();//生成随机数,rand() 生成的是0~32767之间的一个随机数。int die = (randomNumber % 11) ;//获得0--10的随机数cout<<"You rolled a :"<<die<<endl;cin.get();cin.get();return 0;}&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP