Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
let double = Double.random(in: -1.2...4.5)
let integer = Int.random(in: .min ... .max)
let unsignedInteger = UInt.random(in: 4...9)
let bool = Bool.random()
var generator = SystemRandomNumberGenerator()
let double2 = Double.random(in: 1.0..<4.2, using: &generator)
let array = ["Cat", "Cow", "Dog", "Sheep"]
if let element = array.randomElement() {
print(element) // e.g Dog
}
let shuffled = array.shuffled()
print(array, shuffled) // e.g ["Cat", "Cow", "Dog", "Sheep"] ["Dog", "Cow", "Sheep", "Cat"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment