c++ 生成隨機數rand()函數的使用:設定範圍

#include
#include<sstream>
#include<fstream>
#include<string>
#include<stdlib.h>
#include<time.h>
#define random(x) (rand()%x)

int main(int args, char **argv)
{
    srand((int)time(0));
    for(int x=0;x<10;x++)
          printf("%d\n",random(5));
    return 0;
     
    

}

參考http://blog.csdn.net/beyond0824/article/details/6009908

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章