ScaMaC  0.8.2
A Scalable Matrix Collection
scamac_rng.h
Go to the documentation of this file.
1 
8 #ifndef SCAMAC_RNG_H
9 #define SCAMAC_RNG_H
10 
11 #include "scamac_error.h"
12 #include <stdint.h>
13 
14 // xorshift random number generator according to Sebastiano Vigna, arxiv:1402.6246
15 // [ ACM Trans. Math. Software 42, 4 (2016) ]
16 
17 typedef uint64_t scamac_rng_seed_ty;
18 
19 typedef struct {
20  uint64_t sinit[16]; // as seeded
21 
22  uint64_t sliceidx;
23  uint64_t prns[1024];
24 
25 } scamac_ransrc_st;
26 
27 ScamacErrorCode scamac_ransrc_alloc(scamac_rng_seed_ty seed, scamac_ransrc_st ** ransrc);
28 ScamacErrorCode scamac_ransrc_free(scamac_ransrc_st * ransrc);
29 
30 ScamacErrorCode scamac_ransrc_set_seed(scamac_rng_seed_ty seed, scamac_ransrc_st * ransrc);
31 
32 
33 /* single random numbers from source */
34 // unsigned integer, 64 bits (i>=0)
35 uint64_t scamac_ransrc_uint64(scamac_ransrc_st * ransrc, uint64_t i);
36 
37 // uniform real in [a,b) (i>=0)
38 double scamac_ransrc_double(scamac_ransrc_st *ransrc, double a, double b, uint64_t i);
39 
40 /* random vectors */
41 // get n random uint64_t's, with indices i ... i+n-1
42 ScamacErrorCode scamac_ranvec_uint64(scamac_rng_seed_ty seed, uint64_t iv, uint64_t nv, uint64_t * ranvec);
43 ScamacErrorCode scamac_ranvec_double(scamac_rng_seed_ty seed, uint64_t iv, uint64_t nv, double a, double b, double * ranvec);
44 
48 scamac_rng_seed_ty scamac_rng_string_to_seed(const char *str);
49 
50 scamac_rng_seed_ty scamac_rng_entropy(const char *str);
51 
52 #endif /* SCAMAC_RNG_H */
ScaMaC data structure and macro definitions.
scamac_rng_seed_ty scamac_rng_string_to_seed(const char *str)