let randomIntFrom0To10 = Int.random(in: 1..<10)
let randomFloat = Float.random(in: 0..<1)
// if you want to get a random element in an array
let greetings = ["hey", "hi", "hello", "hola"]
greetings.randomElement()
More Related Contents:
- Swift random float between 0 and 1
- Rounding a double value to x number of decimal places in swift
- Any way to replace characters on Swift String?
- Swift: guard let vs if let
- Is key-value observation (KVO) available in Swift?
- Share data between main App and Widget in SwiftUI for iOS 14
- Differences in NSDateComponents syntax?
- When are argument labels required in Swift?
- NSUserDefaults not working on Xcode beta with Watch OS2
- Cancel a timed event in Swift?
- Dictionary in Swift with Mutable Array as value is performing very slow? How to optimize or construct properly?
- Deleting a Row from a UITableView in Swift?
- Calculate age from birth date using NSDateComponents in Swift
- Is there a way to reset the app between tests in Swift XCTest UI?
- Keep window always on top?
- Saving CGImageRef to a png file?
- Swift – Extra Argument in call
- Swift: Converting a string into a variable name
- Selecting global or object print function
- How do I get a reference to the AppDelegate in Swift?
- NSAttributedString, change the font overall BUT keep all other attributes?
- Swift Array – Check if an index exists
- Swift 2.0 : ‘enumerate’ is unavailable: call the ‘enumerate()’ method on the sequence
- PreviewProvider and ObservedObject properties
- A Swift protocol requirement that can only be satisfied by using a final class
- Swift Spritekit Adding Button programmatically
- Saving WebView to PDF returns blank image?
- Swift: shortcut unwrapping of array of optionals
- How do I perform an auto-segue in Xcode 6 using Swift?
- Can Swift convert a class / struct data into dictionary?