/***************随机生成彩票号码(双色球)***/
/**************编译器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");
}