File: tworands.c

package info (click to toggle)
scsitools 0.12-3
  • links: PTS
  • area: main
  • in suites: buster
  • size: 1,244 kB
  • sloc: ansic: 6,043; tcl: 2,144; sh: 923; makefile: 100
file content (26 lines) | stat: -rw-r--r-- 660 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* Simply utility to get two random numbers which is only
   supported by extended tcl, s.t. we need a script for it */

#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>

int main(int argc, char **argv) {
    struct timeval tv;

    if (argc != 1) {
	fputs("Usage: tworands\n"
	      "\tprint two random integers in range 1..25\n", stderr);
	return 2;
    }
    gettimeofday(&tv, NULL);
    srand((unsigned)(tv.tv_sec + tv.tv_usec));
    srand((unsigned)rand());
    srand((unsigned)rand());
    printf("%d %d\n",
	1 + (int)(24.0 * rand() / (RAND_MAX + 1.0)),
	1 + (int)(24.0 * rand() / (RAND_MAX + 1.0))
    );
    return 0;
}