summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--stc/crandom.h17
1 files changed, 9 insertions, 8 deletions
diff --git a/stc/crandom.h b/stc/crandom.h
index 1e3b2107..a3d0b77c 100644
--- a/stc/crandom.h
+++ b/stc/crandom.h
@@ -94,15 +94,16 @@ STC_INLINE double crandom_f64(crandom_eng64_t* rng) {
STC_INLINE crandom_distrib_i64_t crandom_uniform_i64_init(int64_t low, int64_t high) {
crandom_distrib_i64_t dist = {low, high - low + 1}; return dist;
}
-STC_INLINE int64_t crandom_uniform_i64(crandom_eng64_t* rng, crandom_distrib_i64_t dist) {
-#if defined(__SIZEOF_INT128__)
- return dist.offset + (int64_t) (((__uint128_t) crandom_i64(rng) * dist.range) >> 64);
-#elif defined(_MSC_VER) && defined(_WIN64)
- int64_t hi; _umul128(crandom_i64(rng), dist.range, &hi); return dist.offset + hi;
-#else
- return dist.offset + crandom_i64(rng) % dist.range; // slower
-#endif
+STC_INLINE int64_t crandom_uniform_i64(crandom_eng64_t* rng, crandom_distrib_i64_t dist) {
+ #if defined(__SIZEOF_INT128__)
+ return dist.offset + (int64_t) (((__uint128_t) crandom_i64(rng) * dist.range) >> 64);
+ #elif defined(_MSC_VER) && defined(_WIN64)
+ uint64_t _umul128(uint64_t x, uint64_t y, uint64_t *hi);
+ uint64_t hi; _umul128(crandom_i64(rng), dist.range, &hi); return dist.offset + hi;
+ #else
+ return dist.offset + crandom_i64(rng) % dist.range; // slower
+ #endif
}
STC_INLINE crandom_distrib_f64_t crandom_uniform_f64_init(double low, double high) {