1 /* mk-tdata.c - Create some simple random testdata
2 * Copyright (C) 1998, 1999, 2000, 2001, 2006 Free Software Foundation, Inc.
3 *
4 * This file is free software; as a special exception the author gives
5 * unlimited permission to copy and/or distribute it, with or without
6 * modifications, as long as this notice is preserved.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
10 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 */
12
13 #include <config.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <unistd.h>
18
19
20 #ifndef RAND_MAX /* for SunOS */
21 #define RAND_MAX 32767
22 #endif
23
24 int
main(int argc,char ** argv)25 main(int argc, char **argv)
26 {
27 int i, c = 0;
28 int limit =0;
29 int char_mode = 0;
30
31 if (argc)
32 {
33 argc--;
34 argv++;
35 }
36
37 /* Check for option --char N */
38 if (argc > 1 && !strcmp (argv[0], "--char"))
39 {
40 char_mode = 1;
41 c = strtol (argv[1], NULL, 0);
42 argc -= 2;
43 argv += 2;
44 }
45
46 limit = argc ? atoi(argv[0]) : 0;
47
48 srand(getpid());
49
50 for (i=0; !limit || i < limit; i++ )
51 {
52 if (char_mode)
53 {
54 putchar (c);
55 }
56 else
57 {
58 #ifdef HAVE_RAND
59 c = ((unsigned)(1 + (int) (256.0*rand()/(RAND_MAX+1.0)))-1);
60 #else
61 c = ((unsigned)(1 + (int) (256.0*random()/(RAND_MAX+1.0)))-1);
62 #endif
63 putchar (c);
64 }
65 }
66 return 0;
67 }
68