Mercurial > hg > Members > nobuyasu > CbC
changeset 25:844c7b5d74ab draft
add random.c
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 13 Aug 2012 04:35:04 +0900 |
parents | 5354e0f8f557 |
children | 393759114f3a |
files | compare/tree/random.c |
diffstat | 1 files changed, 21 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/compare/tree/random.c Mon Aug 13 04:35:04 2012 +0900 @@ -0,0 +1,21 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +int main(int argc, char *argv[]) +{ + if (argc < 2) { + printf("usage: ./random num [seed]\n"); + exit(0); + } + if (argc > 2) srand((unsigned int)argv[2]); + + int n = atoi(argv[1]); + int i; + for (i=0; i<n; i++) { + printf("%d ",random()%100); + } + puts(""); + + return 0; +}