xs/rng.c

filter: Statementstmt 0.0% 0 / 29 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 35 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/ranlxd.c ↑ Summary xs/sandy_rng.h »
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 0 gsl_rng_alloc (const gsl_rng_type * T)
17 {
18 0 gsl_rng *r = (gsl_rng *) malloc (sizeof (gsl_rng));
19  
20 0 ▶ if (r == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (r == NULL) 0 0 0
21 0 error ("failed to allocate space for rng struct");
22  
23 0 r->state = calloc (1, T->size);
24  
25 0 ▶ if (r->state == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (r->state == NULL) 0 0 0
26 {
27 0 free (r);
28 0 error ("failed to allocate space for rng state");
29 }
30  
31 0 r->type = T;
32  
33 0 gsl_rng_set (r, GSL_RNG_DEFAULT_SEED);
34  
35 0 return r;
36 }
37  
38 void
39 0 gsl_rng_set (const gsl_rng * r, unsigned long int seed)
40 {
41 0 (r->type->set) (r->state, seed);
42 0 }
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 ▶ if (r == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (r == NULL) 0 0 0
78 0 return;
79 0 free (r->state);
80 0 free (r);
81 }
« xs/ranlxd.c ↑ Summary xs/sandy_rng.h »