|
发表于 2008-6-14 17:17:29
|
显示全部楼层
随便写个~~
- unsigned int rand(unsigned int max)
- {
- unsigned int i=0,j;
- if (max<RAND_MAX)
- {
- j = RAND_MAX / (++max) * max;
- for(i=rand(); i>=j; i=rand())
- ;
- return i % max;
- }
- else
- {
- j = max/RAND_MAX;
- for(i=rand()*(j+1)+rand(j); i>max; i=rand()*(j+1)+rand(j))
- ;
- return i;
- }
- }
- char* GetSXNum(char* outStr)
- {
- static char ranStr1[11] = "0123456789";
- char ranStr2[10] = "8RT2j67dK";
- srand(GetCurrentTime());
- char i=0,j=9,k;
- for(;i<4;i++)
- {
- k=rand(--j);
- outStr[i]=ranStr2[k];
- ranStr2[k]=ranStr2[j];
- }
- for(;i<8;i++)
- outStr[i]=ranStr1[rand(9)];
- for(;i<12;i++)
- {
- k=rand(--j);
- outStr[i]=ranStr2[k];
- ranStr2[k]=ranStr2[j];
- }
- return outStr;
- }
复制代码 |
|