trinity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 5/7] Simplify get_interesting_16bit_value()
Date: Wed,  4 Mar 2015 13:11:54 -0800	[thread overview]
Message-ID: <1425503514-38147-1-git-send-email-tyson.w.smith@gmail.com> (raw)

From: Tyson Smith <tyson.w.smith@gmail.com>

Removed values that overlap with get_interesting_8bit_value() and others
that are covered by the 2^n case and 2^n with plus_minus_two().
---
 interesting-numbers.c | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)

diff --git a/interesting-numbers.c b/interesting-numbers.c
index 311b16d..070ddfa 100644
--- a/interesting-numbers.c
+++ b/interesting-numbers.c
@@ -31,28 +31,14 @@ static unsigned char get_interesting_8bit_value(void)
 	}
 }
 
-static int get_interesting_16bit_value(void)
+static unsigned short get_interesting_16bit_value(void)
 {
-	int num = 0;
-
-	switch (rand() % 7) {
-	case 0:	num = 0;
-		break;
-	case 1:	num = -32768;
-		break;
-	case 2:	num = -129;
-		break;
-	case 3:	num = 255;
-		break;
-	case 4:	num = 32767;
-		break;
-	case 5:	num = 1UL << (rand() % 15);
-		break;
-	case 6:	num = rand() % 0xffff;
-		break;
+	switch (rand() % 4) {
+	case 0: return 0x8000 >> (rand() & 7);		// 2^n (0x100 -> 0x8000)
+	case 1: return rand() & 0xffff;				// 0 -> 0xffff
+	case 2: return 0xff00 | (rand() & 0xff);	// 0xff00 -> 0xffff
+	default: return 0xffff;						// max
 	}
-
-	return num;
 }
 
 static unsigned int get_interesting_32bit_value(void)
-- 
1.9.1

                 reply	other threads:[~2015-03-04 21:11 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=1425503514-38147-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 NNTP newsgroup(s).