WEB开发网
开发学院软件开发C++ 生成随机数(数字,大小字母) 阅读

生成随机数(数字,大小字母)

 2012-05-17 16:24:11 来源:WEB开发网   
核心提示:#include <iostream>#include <stdlib.h>#include <time.h>using namespace std;int main(void){ int ran_num; srand((unsigned)time(NULL)); for (int
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main(void)
{
 int ran_num;
 srand((unsigned)time(NULL));
 
 for (int i=0; i<4; i++)
 {
       switch((rand()%3))
       {
             case 1:
             ran_num = 65;
             ran_num += rand()%26;
             putchar(ran_num);
             break;
   
            case 2:
            ran_num = 97;
            ran_num += rand()%26;
            putchar(ran_num);
            break;
            default:
            ran_num = 48;
            ran_num += rand()%9;
            putchar(ran_num);
            break;
      }
 }
 cout<<endl;
 return 0;
}

Tags:生成 随机数 数字

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接