]> www.infradead.org Git - mtd-utils.git/commitdiff
nandtest: seed random generator with time
authorBrian Norris <computersforpeace@gmail.com>
Fri, 2 Dec 2011 17:46:12 +0000 (09:46 -0800)
committerArtem Bityutskiy <Artem.Bityutskiy@intel.com>
Mon, 5 Dec 2011 06:27:31 +0000 (08:27 +0200)
If a seed is not provided via --seed, we use the default rand() values,
which produces the same sequence of values every run. Since this is
undesirable, we should choose a random seed via the current time().

Note that this patch moves the srand() until after all the initial
options processing.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@intel.com>
nandtest.c

index b3aacaff35f6e89f98e0469720e1a34c09653208..0187b877e713669363a38cc1ae9c2679978ae889 100644 (file)
@@ -140,6 +140,8 @@ int main(int argc, char **argv)
        uint32_t offset = 0;
        uint32_t length = -1;
 
+       seed = time(NULL);
+
        for (;;) {
                static const char *short_options="hkl:mo:p:s:";
                static const struct option long_options[] = {
@@ -173,7 +175,6 @@ int main(int argc, char **argv)
 
                case 's':
                        seed = atol(optarg);
-                       srand(seed);
                        break;
 
                case 'p':
@@ -244,6 +245,8 @@ int main(int argc, char **argv)
        printf("Bad blocks     : %d\n", oldstats.badblocks);
        printf("BBT blocks     : %d\n", oldstats.bbtblocks);
 
+       srand(seed);
+
        for (pass = 0; pass < nr_passes; pass++) {
                loff_t test_ofs;