line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#include <stdio.h> |
2
|
|
|
|
|
|
|
#include <stdlib.h> |
3
|
|
|
|
|
|
|
#include <string.h> |
4
|
|
|
|
|
|
|
#include <errno.h> |
5
|
|
|
|
|
|
|
#include "sandy_rng.h" |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#define GSL_RNG_DEFAULT_SEED 1717 |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#define error(msg) \ |
10
|
|
|
|
|
|
|
do { \ |
11
|
|
|
|
|
|
|
fprintf (stderr, msg ": %s\n" , strerror (errno)); \ |
12
|
|
|
|
|
|
|
abort (); \ |
13
|
|
|
|
|
|
|
} while (0) |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
gsl_rng * |
16
|
118
|
|
|
|
|
|
gsl_rng_alloc (const gsl_rng_type * T) |
17
|
|
|
|
|
|
|
{ |
18
|
118
|
|
|
|
|
|
gsl_rng *r = (gsl_rng *) malloc (sizeof (gsl_rng)); |
19
|
|
|
|
|
|
|
|
20
|
118
|
50
|
|
|
|
|
if (r == NULL) |
21
|
0
|
|
|
|
|
|
error ("failed to allocate space for rng struct"); |
22
|
|
|
|
|
|
|
|
23
|
118
|
|
|
|
|
|
r->state = calloc (1, T->size); |
24
|
|
|
|
|
|
|
|
25
|
118
|
50
|
|
|
|
|
if (r->state == NULL) |
26
|
|
|
|
|
|
|
{ |
27
|
0
|
|
|
|
|
|
free (r); |
28
|
0
|
|
|
|
|
|
error ("failed to allocate space for rng state"); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
118
|
|
|
|
|
|
r->type = T; |
32
|
|
|
|
|
|
|
|
33
|
118
|
|
|
|
|
|
gsl_rng_set (r, GSL_RNG_DEFAULT_SEED); |
34
|
|
|
|
|
|
|
|
35
|
118
|
|
|
|
|
|
return r; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
void |
39
|
236
|
|
|
|
|
|
gsl_rng_set (const gsl_rng * r, unsigned long int seed) |
40
|
|
|
|
|
|
|
{ |
41
|
236
|
|
|
|
|
|
(r->type->set) (r->state, seed); |
42
|
236
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
unsigned long int |
45
|
0
|
|
|
|
|
|
gsl_rng_max (const gsl_rng * r) |
46
|
|
|
|
|
|
|
{ |
47
|
0
|
|
|
|
|
|
return r->type->max; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
unsigned long int |
51
|
0
|
|
|
|
|
|
gsl_rng_min (const gsl_rng * r) |
52
|
|
|
|
|
|
|
{ |
53
|
0
|
|
|
|
|
|
return r->type->min; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
const char * |
57
|
0
|
|
|
|
|
|
gsl_rng_name (const gsl_rng * r) |
58
|
|
|
|
|
|
|
{ |
59
|
0
|
|
|
|
|
|
return r->type->name; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
size_t |
63
|
0
|
|
|
|
|
|
gsl_rng_size (const gsl_rng * r) |
64
|
|
|
|
|
|
|
{ |
65
|
0
|
|
|
|
|
|
return r->type->size; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
void * |
69
|
0
|
|
|
|
|
|
gsl_rng_state (const gsl_rng * r) |
70
|
|
|
|
|
|
|
{ |
71
|
0
|
|
|
|
|
|
return r->state; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
void |
75
|
0
|
|
|
|
|
|
gsl_rng_free (gsl_rng * r) |
76
|
|
|
|
|
|
|
{ |
77
|
0
|
0
|
|
|
|
|
if (r == NULL) |
78
|
0
|
|
|
|
|
|
return; |
79
|
0
|
|
|
|
|
|
free (r->state); |
80
|
0
|
|
|
|
|
|
free (r); |
81
|
|
|
|
|
|
|
} |