[go: up one dir, main page]

File: id.c

package info (click to toggle)
fakepop 10
  • links: PTS
  • area: main
  • in suites: lenny, squeeze
  • size: 124 kB
  • ctags: 39
  • sloc: ansic: 397; makefile: 82; sh: 26
file content (38 lines) | stat: -rw-r--r-- 786 bytes parent folder | download | duplicates (4)
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
/* $Id: id.c,v 1.1.1.1 2004/11/30 19:34:52 pzn Exp $ */

#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>

#include "id.h"

static char id_char[] = { "0123456789"
			  "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
			  "abcdefghijklmnopqrstuvwxyz" };

void rnd_init (int init_value) {
  static int rnd_base = 0;
  if (rnd_base == 0) {
    rnd_base = (getpid() << 8) + time(NULL);
  }
  srand(rnd_base + init_value);
}

void id_get_msgid (int n, char * msgid) {
  int i;
  rnd_init(n);
  for (i=0; i<20; i++) {
    msgid[i] = id_char[(int) (62.0*rand()/(RAND_MAX+1.0))];
  }
  msgid[i] = 0;
}

void id_get_uidl (int n, char * uidl) {
  int i;
  rnd_init(n ^ 0xabcd);
  for (i=0; i<20; i++) {
    uidl[i] = id_char[(int) (62.0*rand()/(RAND_MAX+1.0))];
  }
  uidl[i] = 0;
}