From: Brian Norris <computersforpeace@gmail.com>
To: <linux-mtd@lists.infradead.org>
Cc: Jan Weitzel <j.weitzel@phytec.de>,
Brian Norris <computersforpeace@gmail.com>,
Artem Bityutskiy <dedekind1@gmail.com>
Subject: [PATCH] nandtest: seed random generator properly
Date: Mon, 28 Nov 2011 10:11:52 -0800 [thread overview]
Message-ID: <1322503912-8221-1-git-send-email-computersforpeace@gmail.com> (raw)
In-Reply-To: <CAN8TOE-rh_yh_0hi+unXe3Q5zV9tdBW6rhomRG-h3za5A4ROrg@mail.gmail.com>
This patch fixes two problems in nandtest:
(1) if a seed is provided it is actually not used. First call is
"seed = rand()" killing the given seed.
Credit: Jan Weitzel <j.weitzel@phytec.de>
(2) if a seed is not provided, we use the default rand() values, which
produces the same sequence of values every run. It makes more sense
to seed with the time to produce more random sequences.
Cc: Jan Weitzel <j.weitzel@phytec.de>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
Jan: This is an amendment to your patch. Feel free to add a
"Signed-off-by" if this works for you.
nandtest.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/nandtest.c b/nandtest.c
index dc28d09..8cdc816 100644
--- a/nandtest.c
+++ b/nandtest.c
@@ -35,7 +35,7 @@ struct mtd_info_user meminfo;
struct mtd_ecc_stats oldstats, newstats;
int fd;
int markbad=0;
-int seed;
+int seed = -1;
int erase_and_write(loff_t ofs, unsigned char *data, unsigned char *rbuf)
{
@@ -192,6 +192,10 @@ int main(int argc, char **argv)
if (argc - optind != 1)
usage();
+ if (seed < 0)
+ seed = time(NULL);
+ srand(seed);
+
fd = open(argv[optind], O_RDWR);
if (fd < 0) {
perror("open");
--
1.7.5.4
next prev parent reply other threads:[~2011-11-28 18:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-24 10:57 [PATCH] nandtest: use seed argument Jan Weitzel
2011-11-28 17:56 ` Brian Norris
2011-11-28 18:11 ` Brian Norris [this message]
2011-11-29 7:30 ` Antwort: [PATCH] nandtest: seed random generator properly Jan Weitzel
2011-11-30 18:24 ` Brian Norris
2011-12-01 8:23 ` Jan Weitzel
2011-12-01 9:05 ` Artem Bityutskiy
2011-12-02 17:46 ` [PATCH v2] nandtest: seed random generator with time Brian Norris
2011-12-05 6:30 ` Artem Bityutskiy
2011-12-01 7:56 ` [PATCH] nandtest: use seed argument Artem Bityutskiy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1322503912-8221-1-git-send-email-computersforpeace@gmail.com \
--to=computersforpeace@gmail.com \
--cc=dedekind1@gmail.com \
--cc=j.weitzel@phytec.de \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).