]> git.ipfire.org Git - thirdparty/util-linux.git/blob - misc-utils/mcookie.c
Imported from util-linux-2.2 tarball.
[thirdparty/util-linux.git] / misc-utils / mcookie.c
1 /* mcookie.c -- Generates random numbers for xauth
2 * Created: Fri Feb 3 10:42:48 1995 by faith@cs.unc.edu
3 * Revised: Sun Feb 12 20:29:58 1995 by faith@cs.unc.edu
4 * Public Domain 1995 Rickard E. Faith (faith@cs.unc.edu)
5 * This program comes with ABSOLUTELY NO WARRANTY.
6 *
7 * mcookie.c,v 1.1.1.1 1995/02/22 19:09:16 faith Exp
8 */
9
10 #define SECURE 1
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #if SECURE
15 #include <sys/time.h>
16 #include <unistd.h>
17 #endif
18
19 int main( void )
20 {
21 int i;
22 #if SECURE
23 struct timeval tv;
24 struct timezone tz;
25
26 gettimeofday( &tv, &tz );
27 srand( tv.tv_sec + tv.tv_usec );
28 #else
29 long int t;
30
31 time( &t );
32 srand( t );
33 #endif
34
35 for (i = 0; i < 32; i++) {
36 int r = (rand() & 0x0f0) >> 4;
37
38 if (r < 10) putchar( '0' + r );
39 else putchar( 'a' + r - 10 );
40 }
41 putchar ( '\n' );
42
43 return 0;
44 }