Swiftpack.co - quells/Squall as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by quells.
quells/Squall 1.3.3
A pseudo-random number generator written in Swift.
⭐️ 5
🕓 3 years ago
.package(url: "https://github.com/quells/Squall.git", from: "1.3.3")

Squall

A pseudo-random number generator written in Swift. Implements the Mersenne Twister (MT) algorithm as described here.

Mersenne.swift

Implementation of the MT algorithm for 32-bit integers.

Squall.swift

Wrapper around the MT implementation that provides random values for several types:

  • UInt32
  • UInt64
  • Float
  • Double

Provides both uniform and Gaussian (normal) distributions for Float and Double.

Thread Safety

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()
	}
}

Changelog

1.3.3 - March 3, 2021

  • Updated package.swift for use in 5.0+ projects (ht @heckj)

1.3.2 - February 5, 2021

  • Fixed two integer overflow exceptions which could occur during initialization (ht @barrypress).

1.3.1 - February 4, 2021

  • Fixed typo in Mersenne generator (ht @barrypress).

1.3 - October 4, 2018

  • Added OS guards around Squall because DispatchQueue is not always available on Linux systems.
  • Added conformance to RandomNumberGenerator to Gust so that it can be used with the unified Swift 4.2 random methods.

1.2.1 - June 6, 2018

  • Changed instances of M_PI to Double.pi and Float.pi - credit to @jmmaloney4

1.2 - February 19, 2017

  • Changed safeMultiply() to discardMultiply to better describe what the function does.
  • Added a serial queue to Squall for thread safety.
  • Added Gust: a mirror of Squall that is not thread safe but allows parallel execution.

1.1 - February 14, 2017

  • Updated for Swift 3.1
  • Removed Squall.randomData() because the syntax for UnsafeMutablePointer changed.

1.0 - May 21, 2016

  • Initial Release

GitHub

link
Stars: 5
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.3.3
3 years ago

Update package.swift for Swift 5.0+

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics