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
This commit is contained in:
John Baldwin 2005-05-27 15:29:01 +00:00
parent 886f89afda
commit b0a7bd8e88
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=146686

View File

@ -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))