1/*++ 2/* NAME 3/* myrand 3 4/* SUMMARY 5/* rand wrapper 6/* SYNOPSIS 7/* #include <myrand.h> 8/* 9/* void mysrand(seed) 10/* int seed; 11/* 12/* int myrand() 13/* DESCRIPTION 14/* This module implements a wrapper for the portable, pseudo-random 15/* number generator. The wrapper adds automatic initialization. 16/* 17/* mysrand() performs initialization. This call may be skipped. 18/* 19/* myrand() returns a pseudo-random number in the range [0, RAND_MAX]. 20/* If mysrand() was not called, it is invoked with the process ID 21/* ex-or-ed with the time of day in seconds. 22/* LICENSE 23/* .ad 24/* .fi 25/* The Secure Mailer license must be distributed with this software. 26/* WARNING 27/* Do not use this code for generating unpredictable numbers. 28/* AUTHOR(S) 29/* Wietse Venema 30/* IBM T.J. Watson Research 31/* P.O. Box 704 32/* Yorktown Heights, NY 10598, USA 33/*--*/ 34 35/* System library. */ 36 37#include <sys_defs.h> 38#include <stdlib.h> 39#include <unistd.h> 40#include <time.h> 41 42/* Utility library. */ 43 44#include <myrand.h> 45 46static int myrand_initdone = 0; 47 48/* mysrand - initialize */ 49 50void mysrand(int seed) 51{ 52 srand(seed); 53 myrand_initdone = 1; 54} 55 56/* myrand - pseudo-random number */ 57 58int myrand(void) 59{ 60 if (myrand_initdone == 0) 61 mysrand(getpid() ^ time((time_t *) 0)); 62 return (rand()); 63} 64