On Wed, 28 Mar 2012, Jukka Ruohonen wrote:
+ATF_TC_BODY(random_zero, tc)
+{
+       const size_t n = 1000000;
+       size_t i, j;
+       long x;
+
+       srandom(0);
+
+       for (i = j = 0; i < n; i++) {
+
+               if ((x = random()) == 0)
+                       j++;
+       }
+
+       ATF_REQUIRE(j != n);
+}

n=4 would probably be enough iterations, and I'd suggest checking whether all values are the same as each other, rather than checking whether all values are zero.

--apb (Alan Barrett)
From: Alan Barrett <[email protected]>
To: [email protected]
Cc: Bcc: Subject: Re: CVS commit: src Reply-To: In-Reply-To: <[email protected]>

On Wed, 28 Mar 2012, Jukka Ruohonen wrote:
+ATF_TC_BODY(random_zero, tc)
+{
+       const size_t n = 1000000;
+       size_t i, j;
+       long x;
+
+       srandom(0);
+
+       for (i = j = 0; i < n; i++) {
+
+               if ((x = random()) == 0)
+                       j++;
+       }
+
+       ATF_REQUIRE(j != n);
+}

n=4 would probably be enough iterations, and I'd suggest requiring all
values to be different, rather than requiring at least one non-zero
value.

--apb (Alan Barrett)

Reply via email to