明天就要过年了,今天闲着没事,写一个程序
我自己有10万首音乐,写了一个管理音乐的程序,有一个功能是随机在10万首歌中抽取50首音乐发送给客户端,
由于使用rand()生成随机数的范围只能是0到32767,就只能自己修改下,随机出现50个数字,并且不能重复。
为了方便我是用最最最最老的VC6.0,系统是win7;
代码如下
#include "stdafx.h"
#include <Stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char* argv[])
{
srand((unsigned)time(NULL));
int js=0;
int zs=1;
ctbegin:
printf("\t\t\t\t第%d次大循环\n",zs);
head:
js++;
int s_num[50];
int max=40000;
for(int i=0;i<50;i++)//如何MAX小于50,需要更改这里和数值对应
{
begin:
int t=0;
if(max>30000)//rand范围
{
int a=rand()%10;
int b=rand()%10;
int c=rand()%10;
int d=rand()%10;
int e=rand()%10;
int f=rand()%10;
int g=rand()%10;
char str[12]={0};
sprintf(str,"%d%d%d%d%d%d%d",a,b,c,d,e,f,g);
t=atoi(str);
if(t>max)
goto begin;
}
else
{
t=rand()%max;
}
if(t==1