/***************隨機生成彩票號碼(雙色球)***/
/**************編譯器C4droid********************************/
#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<conio.h> //WIN系統為<windows.h>
int main()
{
int a[6],m,n,i,j,x,t,q,y,temp;
printf("生成多少注?\n");
scanf("%d",&x);
printf("\n_________紅球__________|___藍球____\n");
for (t = 1;t <= x; t++)
{
for(i=0;i<=5; i++)
{
sleep(1);
srand((unsigned int)time(NULL)); //rand函數的隨機性存在很大的局限性,不是真正意義上的隨機,此處不做過多討論
a[i] = 1+rand()%33;
for (j = 0; j < i; j++) //除重,理論上不會產生重復數,此處謹防萬一
if (a[i] == a[j])
{
i=i-1;
break;
}
}
sleep(1); //WIN系統為 Sleep(1000)
srand((unsigned int)time(NULL));
q = 1 + rand() %16;
for (m = 0; m<=4; m++) //排序
for (n=m+1;n<=5;n++)
if (a[m] > a[n])
{
temp=a[m];
a[m]=a[n];
a[n]=temp;
}
for (y=0;y<=5;y++)
printf("%02d ",a[y]);
printf(" %02d\n",q);
}
printf("生成完成,共生成【%d】注\n", x);
system("pause");
}