工作中用到的,记下来,用于在Unrealircd系统中生成随机数字串:

static int getRadPass(char *buf)
{
    
int i,j;
    
char mo[10];

    srand((
int)time(0));
    
for(i=0;i<8;i++)
    {
        j
=1+(int)(10.0*rand()/(RAND_MAX+1.0));
        ircsprintf(mo,
"%d",j);
        strcat(buf,mo);
    }
    
return 0;
}
上面代码回返回一个长8位的数字串。
调用时:
    char radpass[10];

    memset(radpass,
0,sizeof(radpass));
    getRadPass(radpass);
    radpass[
8]='\0';

相关文章:

  • 2021-08-01
  • 2022-12-23
  • 2022-12-23
  • 2022-02-19
  • 2021-12-28
  • 2021-07-05
  • 2022-02-28
  • 2021-10-17
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-27
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2022-12-23
相关资源
相似解决方案