工作中用到的,记下来,用于在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位的数字串。
{
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 ;
}
调用时:
char
radpass[
10
];
memset(radpass, 0 , sizeof (radpass));
getRadPass(radpass);
radpass[ 8 ] = ' \0 ' ;
memset(radpass, 0 , sizeof (radpass));
getRadPass(radpass);
radpass[ 8 ] = ' \0 ' ;
本文转自 OldHawk 博客园博客,原文链接:http://www.cnblogs.com/taobataoma/archive/2007/05/11/743240.html
,如需转载请自行联系原作者