1
0
Fork 0

recgen: Add explicit random seed option

This commit is contained in:
Joris van Rantwijk 2022-06-25 11:58:28 +02:00
parent ac37e10e70
commit 99458a6b28
1 changed files with 15 additions and 4 deletions

View File

@ -21,7 +21,7 @@
#define MAX_RECORD_SIZE 65536 #define MAX_RECORD_SIZE 65536
#define REPORT_INTERVAL 100000 #define REPORT_INTERVAL 1000000
namespace { // anonymous namespace namespace { // anonymous namespace
@ -215,7 +215,7 @@ void usage()
"\n" "\n"
"Generate fixed-length random binary records.\n" "Generate fixed-length random binary records.\n"
"\n" "\n"
"Usage: recgen [-a] [-d D] -n N -s S outputfile\n" "Usage: recgen [-a] [-d D] [-S R] -n N -s S outputfile\n"
"\n" "\n"
"Options:\n" "Options:\n"
"\n" "\n"
@ -223,6 +223,7 @@ void usage()
" -d D specify fraction of duplicate records (0.0 to 1.0)\n" " -d D specify fraction of duplicate records (0.0 to 1.0)\n"
" -n N specify number of records (required)\n" " -n N specify number of records (required)\n"
" -s S specify record size in bytes (required)\n" " -s S specify record size in bytes (required)\n"
" -S R specify seed for random generator (default 1)\n"
"\n"); "\n");
} }
@ -236,10 +237,10 @@ int main(int argc, char **argv)
unsigned long long num_records = 0; unsigned long long num_records = 0;
unsigned long record_size = 0; unsigned long record_size = 0;
bool flag_ascii = false; bool flag_ascii = false;
uint64_t seed = 1; unsigned long long seed = 1;
int opt; int opt;
while ((opt = getopt(argc, argv, "ad:n:s:")) != -1) { while ((opt = getopt(argc, argv, "ad:n:s:S:")) != -1) {
char *endptr; char *endptr;
switch (opt) { switch (opt) {
case 'a': case 'a':
@ -278,6 +279,16 @@ int main(int argc, char **argv)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
break; break;
case 'S':
seed = strtoull(optarg, &endptr, 10);
if (endptr == optarg
|| *endptr != '\0'
|| seed > UINT64_MAX) {
fprintf(stderr,
"ERROR: Invalid random seed\n");
return EXIT_FAILURE;
}
break;
case 'h': case 'h':
usage(); usage();
return EXIT_SUCCESS; return EXIT_SUCCESS;