File Coverage

ulib/splitmix.c
Criterion Covered Total %
statement 18 18 100.0
branch 4 4 100.0
condition n/a
subroutine n/a
pod n/a
total 22 22 100.0


line stmt bran cond sub pod time code
1             #ifdef __cplusplus
2             extern "C" {
3             #endif
4              
5             #include "ulib/splitmix.h"
6             #include "ulib/gettime.h"
7             #include "ulib/sysrand.h"
8              
9             #ifdef __cplusplus
10             }
11             #endif
12              
13             /* based on splitmix64
14             * https://xorshift.di.unimi.it/splitmix64.c
15             */
16              
17 215           void uu_splitmix_srand(pUCXT) {
18             unsigned int n;
19             UV ptod[2];
20             U64 sysrand;
21              
22             /* gettimeofday(&tv, 0); */
23 215           (*uu_gettime_U2time)(aTHX_ ptod);
24 215           SMEM->sm_x = (U64)ptod[0] * 1000000
25 215           + (U64)ptod[1];
26              
27             /* stir 16 - 31 times, time-based */
28 215           n = 16 + ((ptod[0] ^ ptod[1]) & 0x0f);
29 5157 100         while (n-- > 0)
30 4942           (void)uu_splitmix_rand(aUCXT);
31              
32 215           uu_sysrand_bytes(&sysrand, 8);
33 215           SMEM->sm_x ^= sysrand;
34              
35             /* stir 16 - 31 times, rand-based */
36 215           n = 16 + (sysrand & 0x0f);
37 5347 100         while (n-- > 0)
38 5132           (void)uu_splitmix_rand(aUCXT);
39 215           }
40              
41 11149           U64 uu_splitmix_rand(pUCXT) {
42 11149           U64 z = (SMEM->sm_x += 0x9e3779b97f4a7c15ULL);
43 11149           z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ULL;
44 11149           z = (z ^ (z >> 27)) * 0x94d049bb133111ebULL;
45 11149           return z ^ (z >> 31);
46             }
47              
48             /* ex:set ts=2 sw=2 itab=spaces: */