From: tyson.w.smith@gmail.com
To: davej@codemonkey.org.uk
Cc: trinity@vger.kernel.org, Tyson Smith <tyson.w.smith@gmail.com>
Subject: [PATCH 2/7] Simplified get_interesting_8bit_value()
Date: Wed, 4 Mar 2015 13:10:28 -0800 [thread overview]
Message-ID: <1425503428-38015-1-git-send-email-tyson.w.smith@gmail.com> (raw)
From: Tyson Smith <tyson.w.smith@gmail.com>
2^n case will now cover up to 128 where previously it only went to 64.
Removed -128, 127, -1 cases, they will be covered by the 2^n and 0xff
cases with plus_minus_two() call.
---
interesting-numbers.c | 30 +++++++++---------------------
1 file changed, 9 insertions(+), 21 deletions(-)
diff --git a/interesting-numbers.c b/interesting-numbers.c
index c0805ab..4b23b4c 100644
--- a/interesting-numbers.c
+++ b/interesting-numbers.c
@@ -20,28 +20,15 @@ static unsigned int plus_minus_two(unsigned int num)
return num;
}
-static char get_interesting_8bit_value(void)
+static unsigned char get_interesting_8bit_value(void)
{
- char num = 0;
-
- switch (rand() % 7) {
- case 0: num = -128;
- break;
- case 1: num = -1;
- break;
- case 2: num = 0;
- break;
- case 3: num = 1;
- break;
- case 4: num = 1UL << (rand() % 7);
- break;
- case 5: num = 127;
- break;
- case 6: num = rand() % 256; // 00-0xff
- break;
+ switch (rand() % 5) {
+ case 0: return 1; // one
+ case 1: return 0xff; // max
+ case 2: return 1UL << (rand() & 7); // 2^n (1 -> 128)
+ case 3: return rand() & 0xff; // 0 -> 0xff
+ default: return 0; // zero
}
-
- return num;
}
static int get_interesting_16bit_value(void)
@@ -103,7 +90,8 @@ unsigned int get_interesting_32bit_value(void)
break;
}
- num = plus_minus_two(num);
+ num = rand() & 0xf ? num : plus_minus_two(num); // 1 in 16 call plus_minus_two
+
return num;
}
--
1.9.1
reply other threads:[~2015-03-04 21:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1425503428-38015-1-git-send-email-tyson.w.smith@gmail.com \
--to=tyson.w.smith@gmail.com \
--cc=davej@codemonkey.org.uk \
--cc=trinity@vger.kernel.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 read-only IMAP folder(s) and NNTP newsgroup(s).