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 264           void uu_splitmix_srand(pUCXT) {
18             unsigned int n;
19             UV ptod[2];
20             U64 sysrand;
21              
22             /* gettimeofday(&tv, 0); */
23 264           (*uu_gettime_U2time)(aTHX_ ptod);
24 264           SMEM->sm_x = (U64)ptod[0] * 1000000
25 264           + (U64)ptod[1];
26              
27             /* stir 16 - 31 times, time-based */
28 264           n = 16 + ((ptod[0] ^ ptod[1]) & 0x0f);
29 6303 100         while (n-- > 0)
30 6039           (void)uu_splitmix_rand(aUCXT);
31              
32 264           uu_sysrand_bytes(&sysrand, 8);
33 264           SMEM->sm_x ^= sysrand;
34              
35             /* stir 16 - 31 times, rand-based */
36 264           n = 16 + (sysrand & 0x0f);
37 6366 100         while (n-- > 0)
38 6102           (void)uu_splitmix_rand(aUCXT);
39 264           }
40              
41 13461           U64 uu_splitmix_rand(pUCXT) {
42 13461           U64 z = (SMEM->sm_x += 0x9e3779b97f4a7c15ULL);
43 13461           z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ULL;
44 13461           z = (z ^ (z >> 27)) * 0x94d049bb133111ebULL;
45 13461           return z ^ (z >> 31);
46             }
47              
48             /* ex:set ts=2 sw=2 itab=spaces: */