/* Copyright 2005 Daniel Cer (daniel.cer@cs.colorado.edu) This work is licensed under the Creative Commons Attribution-NonCommercial- ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/ or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA. */ #include #include /* n_i=65539*n_(i-1) mod 2**31 */ int randu() { static int n=1; return n=((n<<16)+(n<<1)+n)&0x7FFFFFFF; } int main(int argc, char *argv[]) { int max_iter, r, i; char *parse_stop; if (argc != 2) { fprintf(stderr, "Usage:\n\t%s (number of random values to generate*)\n" "\n* '0' --> unlimited\n", argv[0]); return EXIT_FAILURE; } max_iter = strtol(argv[1], &parse_stop, 10); if (*parse_stop != '\0') { fprintf(stderr, "Error: parameter must be an integer value\n"); return EXIT_FAILURE; } else if (max_iter < 0) { fprintf(stderr, "Error: parameter must be non-negative\n"); return EXIT_FAILURE; } for (i = 0; i < max_iter || !max_iter; i++) printf("%d\n", randu()); return EXIT_SUCCESS; }