diff options
| author | mo khan <mo@mokhan.ca> | 2014-07-25 20:29:43 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-07-25 20:29:43 -0600 |
| commit | fcc94ac4cb8958e6cb038db7b89cd4e4d7f82205 (patch) | |
| tree | ac54a9df0abf0fddaad1b11f604bc7dbf0649d39 | |
| parent | 1d0412b1355276f62ac87aeea1d936e2aa07065b (diff) | |
example of pseudo-random number generator.
| -rw-r--r-- | rand_example.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/rand_example.c b/rand_example.c new file mode 100644 index 0000000..794c754 --- /dev/null +++ b/rand_example.c @@ -0,0 +1,20 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +int main(int argc, const char *argv[]) +{ + int i; + printf("RAND_MAX is %u\n", RAND_MAX); + srand(time(0)); + + printf("random values from 0 to RAND_MAX\n"); + for (i = 0; i < 8; i++) { + printf("%d\n", rand()); + } + printf("random values from 1 to 20\n"); + for (i = 0; i < 8; i++) { + printf("%d\n", (rand()%20) + 1); + } + return 0; +} |
