[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#221441: marked as done (rolldice output is biased)

Your message dated Tue, 12 Sep 2006 11:47:11 -0700
with message-id <E1GNDHr-0001sa-96@spohr.debian.org>
and subject line Bug#221441: fixed in rolldice 1.10-3
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--- Begin Message ---
Package: rolldice
Version: 1.10-1

In rolldice.c, I see:

static int get_random(int sides) {
    unsigned int ret_value;
    if(!(fread(&ret_value, sizeof(unsigned int), 1, ran_dev) == 1)) {
        printf("Error in reading random device!\n");
    return (int)(ret_value % sides);

If sides is not an exact divisor of ret_value then there will be a
slight bias towards lower outputs.  The bias is small (when sides is
small in comparison with UINT_MAX) but since the program is going to the
effort of using a crypto-grade random number source it seems foolish to
ignore it.

The patch below ensures unbiased output by rejecting leftover values of
the sample.  Rejections are fairly rare: the expected number of samples
drawn for any one die roll is only very slightly greater than one (again
assuming that sides is small compared with UINT_MAX).

--- rolldice.c-old      Tue Nov 18 12:13:12 2003
+++ rolldice.c  Tue Nov 18 12:13:48 2003
@@ -28,11 +28,16 @@
 static int get_random(int sides) {
     unsigned int ret_value;
+    unsigned int max = UINT_MAX;
+    max -= max % sides;
     if(!(fread(&ret_value, sizeof(unsigned int), 1, ran_dev) == 1)) {
        printf("Error in reading random device!\n");
+    if (ret_value >= max)
+        goto again;
     return (int)(ret_value % sides);

-- [mdw]

--- End Message ---
--- Begin Message ---
Source: rolldice
Source-Version: 1.10-3

We believe that the bug you reported is fixed in the latest version of
rolldice, which is due to be installed in the Debian FTP archive:

  to pool/main/r/rolldice/rolldice_1.10-3.diff.gz
  to pool/main/r/rolldice/rolldice_1.10-3.dsc
  to pool/main/r/rolldice/rolldice_1.10-3_i386.deb

A summary of the changes between this version and the previous one is

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to 221441@bugs.debian.org,
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
Luis Uribe <acme@eviled.org> (supplier of updated rolldice package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing ftpmaster@debian.org)

Hash: SHA1

Format: 1.7
Date: Thu, 07 Sep 2006 21:33:37 -0500
Source: rolldice
Binary: rolldice
Architecture: source i386
Version: 1.10-3
Distribution: unstable
Urgency: low
Maintainer: Luis Uribe <acme@eviled.org>
Changed-By: Luis Uribe <acme@eviled.org>
 rolldice   - A virtual dice roller
Closes: 221441 377870
 rolldice (1.10-3) unstable; urgency=low
   * New maintainer. Closes: #377870
   * Appling patch for biased result by Mark Wooding <mdw@nsict.org>
     Closes: #221441
 6f582eddecd0272ecc73714c96a9df05 556 games optional rolldice_1.10-3.dsc
 30f0c89c07c083380a7ab8ffa9285676 2714 games optional rolldice_1.10-3.diff.gz
 7859ded0e0393f574f3cf6c57b8d500d 10978 games optional rolldice_1.10-3_i386.deb

Version: GnuPG v1.4.5 (GNU/Linux)


--- End Message ---

Reply to: