michael@0: /* michael@0: * prng.c michael@0: * michael@0: * Command-line pseudo-random number generator michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: #ifdef __OS2__ michael@0: #include michael@0: #include michael@0: #else michael@0: #include michael@0: #endif michael@0: michael@0: #include "bbs_rand.h" michael@0: michael@0: int main(int argc, char *argv[]) michael@0: { michael@0: unsigned char *seed; michael@0: unsigned int ix, num = 1; michael@0: pid_t pid; michael@0: michael@0: if(argc > 1) { michael@0: num = atoi(argv[1]); michael@0: if(num <= 0) michael@0: num = 1; michael@0: } michael@0: michael@0: pid = getpid(); michael@0: srand(time(NULL) * (unsigned int)pid); michael@0: michael@0: /* Not a perfect seed, but not bad */ michael@0: seed = malloc(bbs_seed_size); michael@0: for(ix = 0; ix < bbs_seed_size; ix++) { michael@0: seed[ix] = rand() % UCHAR_MAX; michael@0: } michael@0: michael@0: bbs_srand(seed, bbs_seed_size); michael@0: memset(seed, 0, bbs_seed_size); michael@0: free(seed); michael@0: michael@0: while(num-- > 0) { michael@0: ix = bbs_rand(); michael@0: michael@0: printf("%u\n", ix); michael@0: } michael@0: michael@0: return 0; michael@0: michael@0: }