A pseudo-random number generator written in Swift. Implements the Mersenne Twister (MT) algorithm as described here.
Implementation of the MT algorithm for 32-bit integers.
Wrapper around the MT implementation that provides random values for several types:
Provides both uniform and Gaussian (normal) distributions for Float and Double.
Use Squall
if parallel execution speed is not important. It is a global singleton with a serial queue.
let queues: [DispatchQueue] = // N DispatchQueues
for i in 0 ..< N {
queues[i].async {
// do stuff with Squall.random()
}
}
Use Gust
for parallel, independent PRNG. NOTE that a unique offset must be given given if multiple instances are created in close temporal proximity in order to preserve independence of results.
let queues: [DispatchQueue] = // N DispatchQueues
for i in 0 ..< N {
queues[i].async {
let g_i = Gust(offset: UInt32(i))
// do stuff with g_i.random()
}
}
Squall
because DispatchQueue
is not always available on Linux systems.RandomNumberGenerator
to Gust
so that it can be used with the unified Swift 4.2 random methods.M_PI
to Double.pi
and Float.pi
- credit to @jmmaloney4safeMultiply()
to discardMultiply
to better describe what the function does.Squall
for thread safety.Gust
: a mirror of Squall
that is not thread safe but allows parallel execution.Squall.randomData()
because the syntax for UnsafeMutablePointer
changed.link |
Stars: 5 |
Last commit: 3 years ago |
Update package.swift for Swift 5.0+
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics