After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 621182 - random generation problem
random generation problem
Status: RESOLVED FIXED
Product: gnome-games-superseded
Classification: Deprecated
Component: gtali
unspecified
Other Linux
: Normal normal
: ---
Assigned To: GNOME Games maintainers
GNOME Games maintainers
: 608543 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2010-06-10 09:38 UTC by Robert Roth
Modified: 2010-06-10 23:13 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Robert Roth 2010-06-10 09:38:56 UTC
The function for generating the dice rolls does a simple modulus calculation, as shown below:

int
RollDie (void)
{
  return ((rand () % 6) + 1);
}

However, this isn't really a good way to generate a random number. The low order bits aren't very 'random' in a linear congruential generator and if RAND_MAX doesn't divide evenly into 6 the distribution won't even be uniform.

Another method would be:

int
RollDie (void)
{
  double r = rand() * (1.0 / RAND_MAX);
  return (int)floor(r *6.0) + 1;
}
Comment 1 Christian Persch 2010-06-10 11:43:15 UTC
This is in gtali, not aisleriot.
Comment 2 Robert Roth 2010-06-10 12:25:09 UTC
That's right. Sorry, my mistake.
Comment 3 Robert Ancell 2010-06-10 23:12:44 UTC
*** Bug 608543 has been marked as a duplicate of this bug. ***
Comment 4 Robert Ancell 2010-06-10 23:13:10 UTC
This problem has been fixed in the development version. The fix will be available in the next major software release. Thank you for your bug report.