File tree 1 file changed +17
-4
lines changed
1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change 12
12
func randomUInt64( ) -> UInt64 {
13
13
return UInt64 ( arc4random ( ) ) << 32 | UInt64 ( arc4random ( ) )
14
14
}
15
- #elseif os(Linux)
16
- import SwiftShims
15
+ #elseif os(Linux) || os(FreeBSD)
16
+ import Glibc
17
17
18
18
func randomUInt64( ) -> UInt64 {
19
- return UInt64 ( _swift_stdlib_cxx11_mt19937 ( ) ) << 32 | UInt64 ( _swift_stdlib_cxx11_mt19937 ( ) )
19
+ var randomArray = [ UInt8] ( repeating: 0 , count: 8 )
20
+
21
+ let fd = open ( " /dev/urandom " , O_RDONLY)
22
+ defer {
23
+ close ( fd)
24
+ }
25
+
26
+ let _ = read ( fd, & randomArray, MemoryLayout < UInt8 > . size * 8 )
27
+
28
+ var randomInt : UInt64 = 0
29
+ for i in 0 ..< randomArray. count {
30
+ randomInt = randomInt | ( UInt64 ( randomArray [ i] ) << ( i * 8 ) )
31
+ }
32
+
33
+ return randomInt
20
34
}
21
35
#else
22
36
func randomUInt64( ) -> UInt64 {
23
37
fatalError ( " Unsupported platform " )
24
38
}
25
39
#endif
26
-
You can’t perform that action at this time.
0 commit comments