2 * Copyright (c) 2001, 2003, 2008 Todd C. Miller <Todd.Miller@courtesan.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
26 #endif /* HAVE_STDLIB_H */
30 #endif /* HAVE_UNISTD_H */
34 static unsigned int get_random __P((void));
35 static void seed_random __P((void));
43 char *alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
50 for (cp = path; *cp; cp++)
54 } while (cp >= path && *cp == 'X');
58 for (cp = start; *cp; cp++) {
59 r = get_random % (26 + 26);
63 fd = open(path, O_CREAT|O_EXCL|O_RDWR, S_IRUSR|S_IWUSR);
64 if (fd != -1 || errno != EEXIST)
72 # define SRAND srandom
73 # define SEED_T unsigned int
77 # define SRAND srand48
82 # define SEED_T unsigned int
93 * Seed from time of day and process id multiplied by small primes.
96 seed = (ts.tv_sec % 10000) * 523 + ts.tv_nsec / 1000 * 13 +
97 (getpid() % 1000) * 983;
104 static int initialized;
111 return(RAND() & 0xffffffff);