4 * Copyright (C) 2004, 2005, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2000-2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: genrandom.c,v 1.4 2009/03/07 23:47:45 tbox Exp */
28 #include <isc/stdlib.h>
31 main(int argc
, char **argv
) {
38 printf("usage: genrandom k file\n");
41 k
= strtoul(argv
[1], &endp
, 10);
43 printf("usage: genrandom k file\n");
48 fp
= fopen(argv
[2], "w");
50 printf("failed to open %s\n", argv
[2]);
54 #ifndef HAVE_ARC4RANDOM
58 #ifndef HAVE_ARC4RANDOM
59 unsigned short int x
= (rand() & 0xFFFF);
61 unsigned short int x
= (arc4random() & 0xFFFF);
63 unsigned char c
= x
& 0xFF;
64 if (putc(c
, fp
) == EOF
) {
65 printf("error writing to file\n");
69 if (putc(c
, fp
) == EOF
) {
70 printf("error writing to file\n");