Skip to contentSkip to conversation

Simplify get_interesting_16bit_value()

PATCH In review [email protected] 1 participant 1 message Mar 4, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 5/7 Simplify get_interesting_16bit_value()

From: Tyson Smith <[email protected]>

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(-)
interesting-numbers.c +6 -20
index 311b16d..070ddfa 100644
@@ -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)
Signature · 1 line
1.9.1