[問題] 樂透號碼的產生
請問各位
我希望寫一個程式能跑出樂透開獎的7個號碼(不重覆)
coding如下:
int _tmain(int argc, _TCHAR* argv[])
{
int occupy[42] = {0};
int count = 0;
while( count < 7 )
{
int ltm = lotto_number();
if( occupy[ltm-1] == 0 )
{
occupy[ltm-1] = 1;
cout << ltm << endl;
count++;
}
}
system("pause");
return 0;
}
int lotto_number()
{
srand ( time(NULL) );
int num = rand() % 42;
return num + 1;
}
它雖然可以產生七個不重覆的數字
但那些數字的出現總是由小排到大
並且每個間隔幾乎一定是3或4
這樣似乎不隨機@@?
不曉得哪裡出了問題?
懇請各位不吝解答<(_ _)>
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.5.44
→
11/18 23:36, , 1F
11/18 23:36, 1F
→
11/18 23:38, , 2F
11/18 23:38, 2F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章
-4
5