Installation • Usage • License
RandomKit is a Swift framework that makes random data generation simple and easy.
- Xcode
- Version: 7.0
- Language: Swift 2.0
- OS X
- Compatible With: OS X 10.11
- Deployment Target: OS X 10.9
- iOS
- Compatible With: iOS 9.0
- Deployment Target: iOS 8.0
- watchOS
- Compatible With: watchOS 2.0
- Deployment Target: watchOS 2.0
CocoaPods is a centralized dependency manager for Objective-C and Swift. Go here to learn more.
-
Add the project to your Podfile.
use_frameworks! pod 'RandomKit', '~> 1.4.0'
-
Run
pod install
and open the.xcworkspace
file to launch Xcode. -
Import the RandomKit framework.
import RandomKit
Carthage is a decentralized dependency manager for Objective-C and Swift.
-
Add the project to your Cartfile.
github "nvzqz/RandomKit"
-
Run
carthage update
and follow the additional steps in order to add RandomKit to your project. -
Import the RandomKit framework.
import RandomKit
Try it out for yourself! Download the repo and open 'RandomKit.playground'.
Fake data can be generated from static methods found in Random
.
Generate a random gender with a 50/50 chance of being "Male" or "Female".
Random.fakeGender()
Generate a random phone number for a given US state.
Random.fakePhoneNumber() // 5808680873
Random.fakePhoneNumber(.Florida) // 7865276359
The default value for state is ._Any
.
Generate a random English honorific for a given type and gender.
Random.fakeEnglishHonorific() // "Prof."
Random.fakeEnglishHonorific(type: .Professional) // "Dr."
Random.fakeEnglishHonorific(type: .Common, gender: .Male) // "Mr."
Random.fakeEnglishHonorific(gender: .Female) // "Lady"
The default values for type and gender are ._Any
and .Either
respectively.
Generate a random Int
from within an interval or 0...100
by default.
Int.random() // An Int within 0 and 100
Int.random(10...20) // An Int within 10 and 20
Generate a random floating point value from within an interval or 0.0...1.0
by
default.
Double.random(-10...10) // -4.03042337718197
Float.random(-10...10) // 5.167088
CGFloat.random() // 0.699803650379181
Bool.random()
and Bit.random()
have a 50/50 chance of being true
and One
respectively.
Generate a random String
or Character
from within a Character
interval or
from an NSCharacterSet
.
String.random(10) // Default: " "..."~" -> "}+[=Ng>$w1"
String.random(10, "A"..."z") // "poUtXJIbv["
String.random(10, .uppercaseLetterCharacterSet()) // ṤՈ𝕮𝝘ꝻṄԱMĐŦ
Character.random() // "#"
Character.random("A"..."z") // "s"
Character.random(.uppercaseLetterCharacterSet()) // "𝝙"
The default random String
length can be changed by altering String.RandomLength
.
All types that conform to SequenceType
and/or CollectionType
have a random
property that returns a random element, or nil
if the collection is empty.
["Bob", "Cindy", "May", "Charles", "Javier"].random // "Charles"
Generate a random NSURL from a list of values.
NSURL.random() // https://medium.com/
// https://stackoverflow.com/
// https://github.com/
// ...
You can change the possible values yourself by altering NSURL.RandomValues
.
Generate a random date between two NSTimeInterval
values, or between 0.0
and NSTimeInterval(UInt32.max)
.
NSDate.random() // "Aug 28, 2006, 3:38 AM"
Generate a random color with or without the alpha being random as well.
NSColor.random() // r 0.694 g 0.506 b 0.309 a 1.0
NSColor.random(alpha: true) // r 0.859 g 0.57 b 0.409 a 0.047
UIColor.random() // r 0.488 g 0.805 b 0.679 a 1.0
UIColor.random(alpha: true) // r 0.444 g 0.121 b 0.602 a 0.085
RandomKit and its assets are released under the MIT License. Assets
can be found in the assets
branch.