c语⾔:⽣成6位数字验证码,随机数种⼦⽤微秒级别头⽂件:#include <sys/time..h>
函数原型:int  gettimeofday(struct timeval *tv, struct timezone *tz);
参数描述:
struct timeval {
time_t  tv_sec;  /*seconds*/
suseconds_t  tv_usec;  /*microseconds:微秒*/
};
struct timezone {
int tz_minuteswest;
int tz_dsttime;
};
⽣成6位数字验证码:
char * get_verification code(char *dest, int n)
{
struct timeval tv;
gettimeofday(&tv, NULL);
srand(tv.tv_usec);
memset(dest, 0, sizeof(dest));
sprintf(dest, "%d", rand()%9+1);/*⾸位不能为0*/
for (int i = 1; i <n; i++)
sprintf(dest+strlen(dest), "%d", rand()%10);
dest[i] = '\0';
c语言struct头文件
return dest;
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。