aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2005-05-27 15:29:01 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2005-05-27 15:29:01 +0000
commitb0a7bd8e8835b968de897253ad7944d195c540e3 (patch)
treed04ed437eec65552e36eb80d0a95f7743ca07d23
parent886f89afda9590e245d0acd389d0090a507ee175 (diff)
downloadsrc-b0a7bd8e8835b968de897253ad7944d195c540e3.tar.gz
src-b0a7bd8e8835b968de897253ad7944d195c540e3.zip
Fix for 64-bit platforms. random() returns values between 0 and RAND_MAX,
and RAND_MAX != LONG_MAX on 64-bit platforms. PR: amd64/81279 Submitted by: Vivek Khera vivek at khera dot org Submitted by: Adriaan de Groot groot at kde dot org MFC after: 1 week
Notes
Notes: svn path=/head/; revision=146686
-rw-r--r--games/random/random.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/games/random/random.c b/games/random/random.c
index 3dae75bd8a13..0e8f1aa426cd 100644
--- a/games/random/random.c
+++ b/games/random/random.c
@@ -158,7 +158,7 @@ main(int argc, char *argv[])
/* Compute a random exit status between 0 and denom - 1. */
if (random_exit)
- return (int)((denom * random()) / LONG_MAX);
+ return (int)((denom * random()) / RAND_MAX);
/*
* Select whether to print the first line. (Prime the pump.)
@@ -166,7 +166,7 @@ main(int argc, char *argv[])
* 0 (which has a 1 / denom chance of being true), we select the
* line.
*/
- selected = (int)(denom * random() / LONG_MAX) == 0;
+ selected = (int)(denom * random() / RAND_MAX) == 0;
while ((ch = getchar()) != EOF) {
if (selected)
(void)putchar(ch);
@@ -176,7 +176,7 @@ main(int argc, char *argv[])
err(2, "stdout");
/* Now see if the next line is to be printed. */
- selected = (int)(denom * random() / LONG_MAX) == 0;
+ selected = (int)(denom * random() / RAND_MAX) == 0;
}
}
if (ferror(stdin))