fixed random dice rolling bug (uneven distribution of 1s)

This commit is contained in:
TLINDEN
2015-08-02 21:19:29 +02:00
parent 3ee9296066
commit 396b832327
3 changed files with 2 additions and 20 deletions

View File

@@ -182,13 +182,6 @@ The program only uses words which contain 7bit \s-1ASCII\s0 letters
<https://xkcd.com/936/>.
.SH "BUGS"
.IX Header "BUGS"
.IP "\(bu" 4
Program rolled dices are using a pseudo random device, thanks
to some yet unknown reason the digits of dice rolls are unevenly
distributed, in fact there are 20% as much 1s as other digits.
.Sp
Use the option b<\-t> with physical dices to mitigate this.
.PP
In order to report a bug, unexpected behavior, feature requests
or to submit a patch, please open an issue on github:
<https://github.com/TLINDEN/diceware/issues>.

View File

@@ -46,18 +46,6 @@ L<https://xkcd.com/936/>.
=head1 BUGS
=over
=item *
Program rolled dices are using a pseudo random device, thanks
to some yet unknown reason the digits of dice rolls are unevenly
distributed, in fact there are 20% as much 1s as other digits.
Use the option b<-t> with physical dices to mitigate this.
=back
In order to report a bug, unexpected behavior, feature requests
or to submit a patch, please open an issue on github:
L<https://github.com/TLINDEN/diceware/issues>.

View File

@@ -89,11 +89,12 @@ unsigned char *toss(int count, int dicenum) {
for(i=0; i<RLEN; i++) {
onedice = rand[i];
onedice &= 7; /* only use the last 3 bits, 0-7 */
onedice %= 6; /* 6 is the max */
if(onedice >= 1 && onedice <= 6) {
tosses[pos] = onedice;
pos++;
}
else
continue;
if(pos == count)
break;
}