Skip to content

Commit 8ef07f2

Browse files
committed
Implemented support for testfilegenerator.cpp to support --skip=value argument which skips the first [value] bytes from the random number generator. This allows to generate the random sequence 10000000th to 10000007th using only 8 bytes instead of 10000008 bytes.
1 parent d717d8a commit 8ef07f2

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

test/testfilegenerator.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ void usage()
6969
printf(" --file: Path of the generated file\n");
7070
printf(" --size: Size of generated file in bytes. Defaults to 1024\n");
7171
printf(" --seed: Define a seed value to initialze the random number generator. Defaults to local time\n");
72+
printf(" --skip: Define the number of random number to skip before dumping to the file. Defaults to 0\n");
7273
printf(" --fill: Name of the filling strategy. Must be one of the following:\n");
7374
printf(" sequential : Insert values from 0x00 to 0xFF into the file. Default option.\n");
7475
printf(" random : Insert random data into the file\n");
@@ -82,7 +83,8 @@ enum RETURN_CODE
8283
MISSING_FILE,
8384
INVALID_FILE_SIZE,
8485
INVALID_FILL_PARAMETER,
85-
INVALID_SEED
86+
INVALID_SEED,
87+
INVALID_SKIP
8688
};
8789

8890
int main(int argc, char **argv)
@@ -93,6 +95,7 @@ int main(int argc, char **argv)
9395
std::string file;
9496
int size = 1024; //in bytes
9597
unsigned int seed = time(NULL);
98+
unsigned int skip = 0;
9699
std::string fill = "sequential";
97100

98101
if (!parseArgument("file", file, argc, argv))
@@ -117,13 +120,24 @@ int main(int argc, char **argv)
117120
if (parseArgument("seed", tmpSeed, argc, argv))
118121
{
119122
seed = tmpSeed;
120-
if (seed <= 0)
123+
if (seed < 0)
121124
{
122125
printf("Error: Invalid seed value!\n");
123126
return INVALID_SEED;
124127
}
125128
}
126129

130+
int tmpSkip = 0;
131+
if (parseArgument("skip", tmpSkip, argc, argv))
132+
{
133+
skip = tmpSkip;
134+
if (skip < 0)
135+
{
136+
printf("Error: Invalid skip value!\n");
137+
return INVALID_SKIP;
138+
}
139+
}
140+
127141
std::string tmpFill;
128142
if (parseArgument("fill", tmpFill, argc, argv))
129143
{
@@ -161,7 +175,15 @@ int main(int argc, char **argv)
161175
//fill file according to fill strategy
162176
if (fill == "random")
163177
{
178+
//init random number generator
164179
srand( seed );
180+
181+
//skip n bytes
182+
for(unsigned int i=0; i<skip; i++)
183+
{
184+
int dummy = rand();
185+
}
186+
165187
//write content
166188
for(int i=0; i<size; i++)
167189
{

0 commit comments

Comments
 (0)