summaryrefslogtreecommitdiffstats
path: root/misc-utils/mcookie.c
blob: d0730eddecaa70ef71c24ca2f0e5cd401270a808 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* mcookie.c -- Generates random numbers for xauth
 * Created: Fri Feb  3 10:42:48 1995 by faith@cs.unc.edu
 * Revised: Sun Feb 12 20:29:58 1995 by faith@cs.unc.edu
 * Public Domain 1995 Rickard E. Faith (faith@cs.unc.edu)
 * This program comes with ABSOLUTELY NO WARRANTY.
 * 
 * mcookie.c,v 1.1.1.1 1995/02/22 19:09:16 faith Exp
 */

#define SECURE 1

#include <stdio.h>
#include <stdlib.h>
#if SECURE
#include <sys/time.h>
#include <unistd.h>
#endif

int main( void )
{
   int      i;
#if SECURE
   struct timeval  tv;
   struct timezone tz;

   gettimeofday( &tv, &tz );
   srand( tv.tv_sec + tv.tv_usec );
#else
   long int t;
   
   time( &t );
   srand( t );
#endif

   for (i = 0; i < 32; i++) {
      int r = (rand() & 0x0f0) >> 4;

      if (r < 10) putchar( '0' + r );
      else        putchar( 'a' + r - 10 );
   }
   putchar ( '\n' );
   
   return 0;
}