In Swift, we can generate a random number using the random(in:)
function. This function takes a range as an argument and returns a random number within that range.
Here's an example of generating a random number between 1 and 100:
main.swift63 chars3 lines
This will print a random integer between 1 and 100.
We can also generate a random number within a specific range by using the random(in:)
function with a different range:
main.swift71 chars3 lines
This will print a random double between -10.0 and 10.0.
gistlibby LogSnag