A Swift Framework to generate and interact with pseudo-random numbers
*** Work in progress, pull requests are welcome! ***
This project has been adapted to Swift 3 syntax
The framework contains a struct called RandomKit, which is the element that has all the functions to interact using random numbers. All the functions are static methods, you don't need to initialize the struct to use any of its methods.
All the functions are using arc4random(), arc4random_uniform() and drand48(), defined in the stdlib. Don't use them for cryptographic purposes.
- Generate a random int number between min and max
- Generate a random float number between min and max
- Generate a random double number between min and max
- Pick up a random element from an array
- Pick up a random element from a dictionary
- Pick up a random element from a string
- Shuffle an array
- Shuffle a dictionary
Returns nil if the min parameter is higher than max. Otherwise it generates a random integer that is between min and max.
Returns nil if the min parameter is higher than max. Otherwise it generates a random float that is between min and max.
Returns nil if the min parameter is higher than max. Otherwise it generates a random double that is between min and max.
Function that returns a random element from the generic array parameter. Returns nil if the array is empty.
Function that returns a random tuple which contains a key and a value from the generic dictionary parameter. Returns nil if the dictionary is empty.
Function that returns a random element (character) of a string.
Function that returns the same array passed as parameter with its members in a random order, or nil if the array is empty.
Function that returns the same dictionary passed as parameter with its members in a random order, or nil if the dictionary is empty.