diff options
author | Simon Rettberg | 2019-02-18 11:55:41 +0100 |
---|---|---|
committer | Simon Rettberg | 2019-02-18 11:55:41 +0100 |
commit | ae69a754244c4e475c8d2591772ca8e005071d83 (patch) | |
tree | 58b3fa7abc2dcfe3c23e1c0ce108950c720826ab /driver/test-yarandom.c | |
parent | Update gitignore (diff) | |
download | xscreensaver-ae69a754244c4e475c8d2591772ca8e005071d83.tar.gz xscreensaver-ae69a754244c4e475c8d2591772ca8e005071d83.tar.xz xscreensaver-ae69a754244c4e475c8d2591772ca8e005071d83.zip |
Update to 5.42
Diffstat (limited to 'driver/test-yarandom.c')
-rw-r--r-- | driver/test-yarandom.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/driver/test-yarandom.c b/driver/test-yarandom.c new file mode 100644 index 0000000..6701ff8 --- /dev/null +++ b/driver/test-yarandom.c @@ -0,0 +1,66 @@ +/* test-yarandom.c --- generate a file of random bytes for analysis. + * xscreensaver, Copyright (c) 2018 Jamie Zawinski <jwz@jwz.org> + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation. No representations are made about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <stdlib.h> +#ifdef HAVE_UNISTD_H +# include <unistd.h> +#endif + +#include <ctype.h> +#include <stdio.h> +#include "yarandom.h" + +char *progname = 0; + +int +main (int argc, char **argv) +{ + unsigned long i, n; + char *f; + FILE *fd; + + progname = argv[0]; + if (argc != 3) + { + fprintf(stderr, "usage: %s bytes outfile\n", argv[0]); + exit(1); + } + + n = atol (argv[1]); + f = argv[2]; + +# undef ya_rand_init + ya_rand_init(0); + + fd = fopen (f, "w"); + if (!fd) { perror (f); exit (1); } + + n /= sizeof(uint32_t); + for (i = 0; i < n; i++) + { + union { uint32_t i; char s[sizeof(uint32_t)]; } rr; + rr.i = random(); + if (! fwrite (rr.s, sizeof(rr.s), 1, fd)) + { + perror ("write"); + exit (1); + } + } + fclose (fd); + fprintf (stderr, "%s: %s: wrote %ld bytes\n", + progname, f, i * sizeof(uint32_t)); + exit(0); +} |