复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>
using namespace std;
int main()
{
char t=1;///判断是否结束循环
while(1)///死循环
{
int left;
///左边界
int right;
///右边界
cout<<"请输入您需要的左右边界:n";
cin>>left>>right;
if(left>=right)
{
cout<<"您的是输入数据不合法,请重新输入.n";
continue;
}
srand( (unsigned)time(NULL) );
/// 截取毫秒
int num=rand()%right + left;
///对右边界取余 极爱左边界
while(!(num>= left && num<=right))
///循环判断随机数在范围内
{
srand( (unsigned)time(NULL) );
}
cout<<"幸运听众的编号 "<<num<<endl;
cout<<"是否继续运行?1:0n";
///吃回车
cin>>t;
if(t=='0')
{
cout<<"欢迎下次使用!n";
break;
}
else if(t=='1');///继续
else
{
cout<<"孙子你找死啊!!!!!"<<endl;
break;
}
}
return 0;
}
最后
以上就是欢呼蜜蜂最近收集整理的关于生成随机数的全部内容,更多相关生成随机数内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复