Re: CVS commit: src

2012-03-29 Thread Alan Barrett

On Wed, 28 Mar 2012, Jukka Ruohonen wrote:

+ATF_TC_BODY(random_zero, tc)
+{
+   const size_t n = 100;
+   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 a...@cequrux.com
To: source-changes-d@NetBSD.org
Cc: 
Bcc: 
Subject: Re: CVS commit: src
Reply-To: 
In-Reply-To: 20120328103358.4bb3317...@cvs.netbsd.org


On Wed, 28 Mar 2012, Jukka Ruohonen wrote:

+ATF_TC_BODY(random_zero, tc)
+{
+   const size_t n = 100;
+   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)


Re: CVS commit: src

2012-03-29 Thread Jukka Ruohonen
On Thu, Mar 29, 2012 at 08:40:53AM +0200, Alan Barrett wrote:
 n=4 would probably be enough iterations, and I'd suggest checking 

Adjusted.

By the way, some general RNG tests should be added too. I vaguely remember
the so-called diehard tests somewhere from the 1990s -- perhaps something
like that?

- Jukka.