[tali] Fix RollDie().



commit e560c7d16517c8181404dcd4d9e6e752c30802cd
Author: Hadi Moshayedi <hadi moshayedi net>
Date:   Sun Jan 3 02:03:05 2016 -0500

    Fix RollDie().
    
    Since rand() returns 0..RAND_MAX inclusive, RollDie() could return 7
    if result of rand() equaled to RAND_MAX.
    
    This change makes sure the result of this function is in 1..6 range.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=760094

 src/yahtzee.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
---
diff --git a/src/yahtzee.c b/src/yahtzee.c
index 905520c..0508a9c 100644
--- a/src/yahtzee.c
+++ b/src/yahtzee.c
@@ -212,8 +212,7 @@ NewGame (void)
 int
 RollDie (void)
 {
-  double r = (double) rand () / RAND_MAX;
-  return (int) (r * 6.0) + 1;
+  return rand () % 6 + 1;
 }
 
 void


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