splitmix 0.1.2 → 0.1.3
raw patch · 5 files changed
+54/−57 lines, 5 files
Files
- Changelog.md +6/−0
- cbits-apple/init.c +8/−0
- cbits-unix/init.c +0/−4
- cbits-win/init.c +4/−23
- splitmix.cabal +36/−30
Changelog.md view
@@ -1,3 +1,9 @@+# 0.1.3++- Use system specific entropy/randomess sources to initialise the default generator.+ Specifically `SecRandomCopyBytes` on Apple platforms and+ `RtlGenRandom` on Windows.+ # 0.1.2 - Use `getentropy` for initialisation on unix-like systems (i.e. not Windows).
+ cbits-apple/init.c view
@@ -0,0 +1,8 @@+#include <stdint.h>+#include <Security/SecRandom.h>++uint64_t splitmix_init() {+ uint64_t result;+ int r = SecRandomCopyBytes(kSecRandomDefault, sizeof(uint64_t), &result);+ return r == errSecSuccess ? result : 0xfeed1000;+}
cbits-unix/init.c view
@@ -1,10 +1,6 @@ #include <stdint.h> #include <unistd.h>--/* for macos */-#ifdef __APPLE__ #include <sys/random.h>-#endif uint64_t splitmix_init() { uint64_t result;
cbits-win/init.c view
@@ -1,28 +1,9 @@ #include <stdint.h>- #include <windows.h>+#include <ntsecapi.h> uint64_t splitmix_init() {- /* Handy list at https://stackoverflow.com/a/3487338/1308058 */-- uint64_t a = GetCurrentProcessId(); /* DWORD */- uint64_t b = GetCurrentThreadId(); /* DWORD */- uint64_t c = GetTickCount(); /* DWORD */-- SYSTEMTIME t = {0,0,0,0,0,0,0,0};- GetSystemTime(&t);-- LARGE_INTEGER i;- QueryPerformanceCounter(&i);-- return a ^ (b << 32) ^ (c << 16)- ^ ((uint64_t) t.wYear << 56)- ^ ((uint64_t) t.wMonth << 48)- ^ ((uint64_t) t.wDayOfWeek << 40)- ^ ((uint64_t) t.wDay << 32)- ^ ((uint64_t) t.wHour << 24)- ^ ((uint64_t) t.wMinute << 16)- ^ ((uint64_t) t.wSecond << 8)- ^ ((uint64_t) t.wMilliseconds << 0)- ^ ((uint64_t) i.QuadPart);+ uint64_t result;+ int r = RtlGenRandom(&result, sizeof(uint64_t));+ return r ? result : 0xfeed1000; }
splitmix.cabal view
@@ -1,6 +1,6 @@-cabal-version: >=1.10+cabal-version: 2.4 name: splitmix-version: 0.1.2+version: 0.1.3 synopsis: Fast Splittable PRNG description: Pure Haskell implementation of SplitMix described in@@ -26,28 +26,30 @@ (the mixing functions are easily inverted, and two successive outputs suffice to reconstruct the internal state). -license: BSD3+license: BSD-3-Clause license-file: LICENSE maintainer: Oleg Grenrus <oleg.grenrus@iki.fi> bug-reports: https://github.com/haskellari/splitmix/issues category: System, Random build-type: Simple tested-with:- GHC ==8.6.5- || ==8.8.4- || ==8.10.4- || ==9.0.2- || ==9.2.8- || ==9.4.8- || ==9.6.7- || ==9.8.4- || ==9.10.2- || ==9.12.2+ GHC ==8.6.5+ || ==8.8.4+ || ==8.10.4+ || ==9.0.2+ || ==9.2.8+ || ==9.4.8+ || ==9.6.7+ || ==9.8.4+ || ==9.10.2+ || ==9.12.2 -extra-source-files:+extra-doc-files: Changelog.md- make-hugs.sh README.md++extra-source-files:+ make-hugs.sh test-hugs.sh flag optimised-mixer@@ -72,7 +74,7 @@ -- ghc-options: -fplugin=DumpCore -fplugin-opt DumpCore:core-html build-depends:- base >=4.12.0.0 && <4.22+ , base >=4.12.0.0 && <4.22 , deepseq >=1.4.4.0 && <1.6 if flag(optimised-mixer)@@ -92,6 +94,10 @@ if os(windows) c-sources: cbits-win/init.c + elif (os(osx) || os(ios))+ c-sources: cbits-apple/init.c+ ld-options: -framework Security+ else c-sources: cbits-unix/init.c @@ -110,7 +116,7 @@ hs-source-dirs: bench main-is: Bench.hs build-depends:- base+ , base , containers >=0.6.0.1 && <0.8 , criterion >=1.6.0.0 && <1.7 , random@@ -124,7 +130,7 @@ hs-source-dirs: bench main-is: SimpleSum.hs build-depends:- base+ , base , random , splitmix @@ -136,7 +142,7 @@ main-is: Range.hs other-modules: Data.Bits.Compat build-depends:- base+ , base , random , splitmix @@ -147,7 +153,7 @@ hs-source-dirs: tests main-is: Examples.hs build-depends:- base+ , base , HUnit >=1.6.0.0 && <1.7 , splitmix @@ -162,7 +168,7 @@ Uniformity build-depends:- base+ , base , containers >=0.4.0.0 && <0.8 , HUnit >=1.6.0.0 && <1.7 , math-functions >=0.3.3.0 && <0.4@@ -177,7 +183,7 @@ hs-source-dirs: tests main-is: SplitMixPi.hs build-depends:- base+ , base , splitmix test-suite montecarlo-pi-32@@ -187,7 +193,7 @@ hs-source-dirs: tests main-is: SplitMixPi32.hs build-depends:- base+ , base , splitmix test-suite splitmix-dieharder@@ -197,15 +203,15 @@ hs-source-dirs: tests main-is: Dieharder.hs build-depends:- async >=2.2.1 && <2.3+ , async >=2.2.1 && <2.3 , base- , bytestring >=0.10.8.2 && <0.13+ , bytestring >=0.10.8.2 && <0.13 , deepseq- , process >=1.6.0.0 && <1.7+ , process >=1.6.0.0 && <1.7 , random , splitmix- , tf-random >=0.5 && <0.6- , vector >=0.13.0.0 && <0.14+ , tf-random >=0.5 && <0.6+ , vector >=0.13.0.0 && <0.14 test-suite splitmix-testu01 if !os(linux)@@ -219,7 +225,7 @@ c-sources: tests/cbits/testu01.c extra-libraries: testu01 build-depends:- base+ , base , base-compat-batteries >=0.10.5 && <0.15 , splitmix @@ -230,6 +236,6 @@ hs-source-dirs: tests main-is: Initialization.hs build-depends:- base+ , base , HUnit >=1.6.0.0 && <1.7 , splitmix