Swift 4.2+
Swift 4.2 shipped with Xcode 10 introduces new easy-to-use random functions for many data types.
You can call the random()
method on numeric types.
let randomInt = Int.random(in: 0..<6)
let randomDouble = Double.random(in: 2.71828...3.14159)
let randomBool = Bool.random()
Related Contents:
- How does one generate a random number in Swift?
- How to generate a random number in a range (10…20) using Swift [duplicate]
- How to make a random color with Swift
- Swift random float between 0 and 1
- Getting a “This application is modifying the autolayout engine from a background thread” error?
- Waiting until the task finishes
- Examples of Delegates in Swift [closed]
- Get random elements from array in Swift
- UITableview with more than One Custom Cells with Swift
- creating custom tableview cells in swift
- Return instancetype in Swift
- dyld: Library not loaded: @rpath/libswift_stdlib_core.dylib
- What is ARAnchor exactly?
- How to get Ip address in swift
- Swift constants: Struct or Enum
- Flatten an Array of Arrays in Swift
- Strange Swift numbers type casting
- Deleting list elements from SwiftUI’s List
- How to move enemy towards a moving player?
- Difference between == and ===
- PhotoPicker discovery error: Error Domain=PlugInKit Code=13
- Checking if an object is a given type in Swift
- Escaping Closures in Swift
- AnyObject and Any in Swift
- Get integer value from string in swift
- Get terminal output after a command swift
- ARKit – What do the different columns in Transform Matrix represent?
- How to get the name of enumeration value in Swift?
- Deleting a Row from a UITableView in Swift?
- How do I declare a variable that has a type and implements a protocol?
- How do I check if a firebase database value exists?
- How do you unwrap Swift optionals?
- Property initializers run before ‘self’ is available
- Swift extension example
- Swift Array – Check if an index exists
- Providing a default value for an Optional in Swift?
- Swift Alamofire: How to get the HTTP response status code
- dispatch_once after the Swift 3 GCD API changes
- UITextView with hyperlink text
- Keep window always on top?
- Changing text color of datepicker
- SwiftUI add inverted mask
- Firebase getting data in order
- SwiftUI – Wait until Firestore getDocuments() is finished before moving on
- Swift 5.1 Error: [plugin] AddInstanceForFactory: No factory registered for id
- How do I use UserDefaults with SwiftUI?
- UIBezierPath: How to add a border around a view with rounded corners?
- ‘Fatal error: index out of range’ when deleting bound object in view
- Generating random numbers with Swift
- Whats the Swift animate WithDuration syntax?