生成随机数

来源:互联网 发布:快餐店数据流程图 编辑:程序博客网 时间:2024/06/07 02:30
#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:0\n";       ///吃回车        cin>>t;        if(t=='0')        {            cout<<"欢迎下次使用!\n";            break;        }        else if(t=='1');///继续        else        {            cout<<"孙子你找死啊!!!!!"<<endl;            break;        }    }    return 0;}
0 0
原创粉丝点击