|
1 /* |
|
2 * prng.c |
|
3 * |
|
4 * Command-line pseudo-random number generator |
|
5 * |
|
6 * This Source Code Form is subject to the terms of the Mozilla Public |
|
7 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
9 |
|
10 #include <stdio.h> |
|
11 #include <stdlib.h> |
|
12 #include <limits.h> |
|
13 #include <time.h> |
|
14 |
|
15 #ifdef __OS2__ |
|
16 #include <types.h> |
|
17 #include <process.h> |
|
18 #else |
|
19 #include <unistd.h> |
|
20 #endif |
|
21 |
|
22 #include "bbs_rand.h" |
|
23 |
|
24 int main(int argc, char *argv[]) |
|
25 { |
|
26 unsigned char *seed; |
|
27 unsigned int ix, num = 1; |
|
28 pid_t pid; |
|
29 |
|
30 if(argc > 1) { |
|
31 num = atoi(argv[1]); |
|
32 if(num <= 0) |
|
33 num = 1; |
|
34 } |
|
35 |
|
36 pid = getpid(); |
|
37 srand(time(NULL) * (unsigned int)pid); |
|
38 |
|
39 /* Not a perfect seed, but not bad */ |
|
40 seed = malloc(bbs_seed_size); |
|
41 for(ix = 0; ix < bbs_seed_size; ix++) { |
|
42 seed[ix] = rand() % UCHAR_MAX; |
|
43 } |
|
44 |
|
45 bbs_srand(seed, bbs_seed_size); |
|
46 memset(seed, 0, bbs_seed_size); |
|
47 free(seed); |
|
48 |
|
49 while(num-- > 0) { |
|
50 ix = bbs_rand(); |
|
51 |
|
52 printf("%u\n", ix); |
|
53 } |
|
54 |
|
55 return 0; |
|
56 |
|
57 } |