C语言之获取32字节随机数的字符串
1、问题
获取32字节随机数的字符串
2、代码实现
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define SIZE 32
void get_rand(char *p, int length) {
char value[10] = "0123456789";
srand(time(NULL));
for (int i = 0; i < length; ++i)
{
*(p + i) = value[rand() % 10];
}
*(p + SIZE) = '\0';
return;
}
int main()
{
unsigned char value[SIZE] = {0};
get_rand(value, SIZE);
printf("value is: %s\n", value);
return 0;
}
3 运行结果
value is: 37395579854277531124503372363886
赞 (0)