C语言之获取32字节随机数的字符串

来源:互联网 发布:2016网络大神新书排行 编辑:程序博客网 时间:2024/05/18 03:48

1、问题

获取32字节随机数的字符串




2、代码实现

#include <stdio.h>#include <time.h>#include <stdlib.h>#include <string.h>#define SIZE 32void 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];count++;}*(p + SIZE) = '\0';return;}int main() {unsigned char value[SIZE] = {0}; printf("before value is: %s\n, length is %d\n", value, strlen(value));get_rand(value, SIZE);printf("before value is: %s\n, length is %d\n", value, strlen(value));}


原创粉丝点击