ulib/splitmix.c

filter: Statementstmt 100% 18 / 18 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 100% 22 / 22 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« ulib/pack.c ↑ Summary ulib/xoshiro.c »
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 204 void uu_splitmix_srand(pUCXT) {
18 unsigned int n;
19 UV ptod[2];
20 U64 sysrand;
21  
22 /* gettimeofday(&tv, 0); */
23 204 (*uu_gettime_U2time)(aTHX_ ptod);
24 204 SMEM->sm_x = (U64)ptod[0] * 1000000
25 204 + (U64)ptod[1];
26  
27 /* stir 16 - 31 times, time-based */
28 204 n = 16 + ((ptod[0] ^ ptod[1]) & 0x0f);
29 4980 ▶ while (n-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (n-- > 0) 4776 204 4980
30 4776 (void)uu_splitmix_rand(aUCXT);
31  
32 204 uu_sysrand_bytes(&sysrand, 8);
33 204 SMEM->sm_x ^= sysrand;
34  
35 /* stir 16 - 31 times, rand-based */
36 204 n = 16 + (sysrand & 0x0f);
37 4981 ▶ while (n-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
while (n-- > 0) 4777 204 4981
38 4777 (void)uu_splitmix_rand(aUCXT);
39 204 }
40  
41 10573 U64 uu_splitmix_rand(pUCXT) {
42 10573 U64 z = (SMEM->sm_x += 0x9e3779b97f4a7c15ULL);
43 10573 z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ULL;
44 10573 z = (z ^ (z >> 27)) * 0x94d049bb133111ebULL;
45 10573 return z ^ (z >> 31);
46 }
47  
48 /* ex:set ts=2 sw=2 itab=spaces: */
« ulib/pack.c ↑ Summary ulib/xoshiro.c »