mirror of
https://github.com/freebsd/freebsd-src.git
synced 2024-11-27 09:12:44 +00:00
Correct an error in the previous revision. RAND_MAX is the maximum value
for rand(3), not random(3). random(3) is defined to return values between 0 and 2^31-1, so add a local RANDOM_MAX constant to this file that is defined as 2^31-1 and use that in place of RAND_MAX. Reviewed by: bde Approved by: re (dwhite) MFC after: 1 week
This commit is contained in:
parent
afc7f38c6b
commit
59c2bcbae9
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=147530
@ -62,6 +62,12 @@ __FBSDID("$FreeBSD$");
|
|||||||
|
|
||||||
#include "randomize_fd.h"
|
#include "randomize_fd.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The random() function is defined to return values between 0 and
|
||||||
|
* 2^31 - 1 inclusive in random(3).
|
||||||
|
*/
|
||||||
|
#define RANDOM_MAX 0x7fffffffL
|
||||||
|
|
||||||
static void usage(void);
|
static void usage(void);
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -158,7 +164,7 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* Compute a random exit status between 0 and denom - 1. */
|
/* Compute a random exit status between 0 and denom - 1. */
|
||||||
if (random_exit)
|
if (random_exit)
|
||||||
return (int)((denom * random()) / RAND_MAX);
|
return (int)((denom * random()) / RANDOM_MAX);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Select whether to print the first line. (Prime the pump.)
|
* Select whether to print the first line. (Prime the pump.)
|
||||||
@ -166,7 +172,7 @@ main(int argc, char *argv[])
|
|||||||
* 0 (which has a 1 / denom chance of being true), we select the
|
* 0 (which has a 1 / denom chance of being true), we select the
|
||||||
* line.
|
* line.
|
||||||
*/
|
*/
|
||||||
selected = (int)(denom * random() / RAND_MAX) == 0;
|
selected = (int)(denom * random() / RANDOM_MAX) == 0;
|
||||||
while ((ch = getchar()) != EOF) {
|
while ((ch = getchar()) != EOF) {
|
||||||
if (selected)
|
if (selected)
|
||||||
(void)putchar(ch);
|
(void)putchar(ch);
|
||||||
@ -176,7 +182,7 @@ main(int argc, char *argv[])
|
|||||||
err(2, "stdout");
|
err(2, "stdout");
|
||||||
|
|
||||||
/* Now see if the next line is to be printed. */
|
/* Now see if the next line is to be printed. */
|
||||||
selected = (int)(denom * random() / RAND_MAX) == 0;
|
selected = (int)(denom * random() / RANDOM_MAX) == 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ferror(stdin))
|
if (ferror(stdin))
|
||||||
|
Loading…
Reference in New Issue
Block a user