1 /* copyright 2016 Apache 2 sddekit authors */
13 static void rng_seed(sd_rng
*r
, uint32_t seed
)
15 struct rng_data
*d
= r
->ptr
;
18 rk_seed(seed
, &d
->rks
);
21 static double rng_norm(sd_rng
*r
)
23 struct rng_data
*d
= r
->ptr
;
24 return rk_gauss(&d
->rks
);
27 static void rng_fill_norm(sd_rng
*r
, uint32_t n
, double *x
)
30 struct rng_data
*d
= r
->ptr
;
32 x
[i
] = rk_gauss(&d
->rks
);
35 static void rng_free(sd_rng
*r
)
41 static uint32_t rng_nbytes(sd_rng
*r
)
44 return sizeof(struct rng_data
) + sizeof(sd_rng
);
47 static sd_rng rng_default
= {
51 .fill_norm
= &rng_fill_norm
,
52 .nbytes
= &rng_nbytes
,
56 sd_rng
*sd_rng_new_default()
59 if ((r
= sd_malloc (sizeof(sd_rng
))) == NULL
60 || (*r
= rng_default
, 0)
61 || (r
->ptr
= sd_malloc (sizeof(struct rng_data
))) == NULL
)
64 sd_err("alloc rng failed.");