trinity.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 6/7] Simplify get_interesting_32bit_value()
@ 2015-03-04 21:12 tyson.w.smith
  0 siblings, 0 replies; only message in thread
From: tyson.w.smith @ 2015-03-04 21:12 UTC (permalink / raw)
  To: davej; +Cc: trinity, Tyson Smith

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

Removed values that overlap with values generated but the other functions.
Added multiple of page_size case.
---
 interesting-numbers.c | 35 +++++++++++------------------------
 1 file changed, 11 insertions(+), 24 deletions(-)

diff --git a/interesting-numbers.c b/interesting-numbers.c
index 070ddfa..4b4e785 100644
--- a/interesting-numbers.c
+++ b/interesting-numbers.c
@@ -43,31 +43,18 @@ static unsigned short get_interesting_16bit_value(void)
 
 static unsigned int get_interesting_32bit_value(void)
 {
-	unsigned int num = 0;
-
-	switch (rand() % 9) {
-	case 0:	num = 0;
-		break;
-	case 1:	num = 1UL << (rand() % 32);	// set a single bit.
-		break;
-	case 2:	num = 0x8fffffff;
-		break;
-	case 3:	num = 0xff;
-		num = num << (rand() % 31);
-		break;
-	case 4: num = 0xffff0000;
-		break;
-	case 5: num = 0xffffe000;
-		break;
-	case 6: num = 0xffffff00 | (rand() % 256);
-		break;
-	case 7: num = 0xffffffff - page_size;
-		break;
-	case 8: num = 0xffffffff;
-		break;
+	switch (rand() % 10) {
+	case 0: return 0x80000000 >> (rand() & 0x1f);	// 2^n (1 -> 0x10000)
+	case 1: return rand();							// 0 -> RAND_MAX (likely 0x7fffffff)
+	case 2: return 0xff << (rand() % 25);
+	case 3: return 0xffff0000;
+	case 4: return 0xffffe000;
+	case 5: return 0xffffff00 | (rand() & 0xff);
+	case 6: return 0xffffffff - page_size;
+	case 7: return page_size;
+	case 8: return page_size * ((rand() % (0xffffffff/page_size)) + 1);
+	default: return 0xffffffff;						// max
 	}
-
-	return num;
 }
 
 #if __WORDSIZE != 32
-- 
1.9.1

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-03-04 21:12 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-04 21:12 [PATCH 6/7] Simplify get_interesting_32bit_value() tyson.w.smith

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).