generate a random number between 1 and 100 in swift

main.swift
let randomNumber = Int(arc4random_uniform(100)) + 1
52 chars
2 lines

In Swift, you can use the arc4random_uniform() function to generate a random integer within a specific range. In this case, arc4random_uniform(100) generates a random integer between 0 and 99, so we add 1 to the result to get a random integer between 1 and 100. Finally, we cast the result to an Int data type.

gistlibby LogSnag