Newer
Older
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
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h> // printf
#include <stdlib.h> // EXIT_SUCCESS
#include "prng_shared.h"
int main(int argc, char* argv[]) {
int seed;
int N;
int i;
double *seq;
// get parameters from command line arguments
read_arguments(&seed, &N, argc, argv);
// allocate and array to hold N random numbers
seq = malloc(N * sizeof(double));
// exit if allocation fails
if (seq == NULL) {
printf("Cannot allocate space for %d numbers\n", N);
exit(EXIT_FAILURE);
}
// generate N random numbers and save them in the array
for (i=0; i<N; i++) {
seq[i] = (double)rand_r(&seed) / (double)RAND_MAX;
}
// print the generated random numbers, showing 8 digits after the decimal point
for (i=0; i<N; i++) {
printf("%10.8lf\n", seq[i]);
}
return EXIT_SUCCESS;
}