1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-14 10:09:48 +00:00

Do not re-initialize random numbers generator several times.

Use ^ getpid() to produce better initial state.
This commit is contained in:
Andrey A. Chernov 1997-03-10 08:04:15 +00:00
parent a1b460b73e
commit 359ceb95ec
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=23603
2 changed files with 12 additions and 4 deletions

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id$
* $Id: chap.c,v 1.10 1997/02/22 16:10:05 peter Exp $
*
* TODO:
*/
@ -41,6 +41,7 @@ struct authinfo AuthChapInfo = {
};
extern char *AuthGetSecret();
extern int randinit;
void
ChapOutput(code, id, ptr, count)
@ -78,7 +79,10 @@ int chapid;
int len, i;
char *cp;
srandom(time(NULL));
if (!randinit) {
srandom((unsigned)(time(NULL) ^ getpid()));
randinit = 1;
}
cp = challenge_data;
*cp++ = challenge_len = random() % 32 + 16;

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.c,v 1.32 1997/02/22 16:10:08 peter Exp $
* $Id: command.c,v 1.33 1997/03/10 06:21:00 ache Exp $
*
*/
#include <sys/types.h>
@ -58,6 +58,7 @@ extern struct cmdtab const SetCommands[];
extern char *IfDevName;
struct in_addr ifnetmask;
int randinit;
static int ShowCommand(), TerminalCommand(), QuitCommand();
static int CloseCommand(), DialCommand(), DownCommand();
@ -653,7 +654,10 @@ char **argv;
if (strcasecmp(argv[0], "random") == 0) {
VarRedialTimeout = -1;
printf("Using random redial timeout.\n");
srandom(time(0));
if (!randinit) {
srandom((unsigned)(time(NULL) ^ getpid()));
randinit = 1;
}
}
else {
timeout = atoi(argv[0]);