* [PATCH 2/7] Simplified get_interesting_8bit_value()
@ 2015-03-04 21:10 tyson.w.smith
0 siblings, 0 replies; only message in thread
From: tyson.w.smith @ 2015-03-04 21:10 UTC (permalink / raw)
To: davej; +Cc: trinity, Tyson Smith
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2015-03-04 21:10 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:10 [PATCH 2/7] Simplified get_interesting_8bit_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).