#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void generate_key(unsigned char* key) {
int i;
for (i=0; i<8; i++) {
key[i] = rand()%255;
}
}
int main(int argc,char *argv[])
{
unsigned char keyfile[8];
FILE *key_file;
key_file = fopen("test.txt", "wb");
if (!key_file)
{
printf("Could not open file to write key.");
return 1;
}
//unsigned int iseed = (unsigned int)time(NULL);
//srand (iseed);
generate_key(keyfile);
int bytes_written = fwrite(keyfile, 1, 8, key_file);
if (bytes_written != 8)
{
printf("Error writing key to output file.");
fclose(key_file);
return 1;
}
return 0;
}
当不执行随机数种子生成函数时,生成的文档为0xa个字节
29 6b d0 be d0 b2 2c d0 95 03 21
执行了随机数生成种子之后,才正好为8个字节