標題:
亂數 - 隨機亂數
[打印本頁]
作者:
周政輝
時間:
2017-9-2 09:43
標題:
亂數 - 隨機亂數
搭配時間函式, 產生20組隨機亂數.
time(NULL)可回傳, 從格林威治時間 1970年1月1號 0時0分0秒開始到現在的秒數.
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
// 38 41 45 48 51 54 58 61 64 68
srand(time(NULL));
for(int i=0;i<20;i++)
{
// 2147483647
cout << rand() << endl;
}
system("pause");
return 0;
}
複製代碼
作者:
莊旻叡
時間:
2017-9-2 09:49
#include<iostream>
#include<cstdlib>
#include<time.h>
using namespace std;
int main()
{
srand(time(NULL));
for(int i=0;i<20;i++)
{
cout<<rand()<<endl;
}
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2