Random Function

Hi I have been watching the Coding With Chris Swift lessons on YouTube and could not get this piece of code to run. I am still learning vocabulary but I was not sure why it was not working. I am using Xcode 9.4. The error I seemed to get was Type ‘Int’ has no member ‘random’. So what am I missing?

class XmasPresent {

static func surprise() -> Int {
    return Int.random(in:1...10)



try returning this:

return Int(arc4random_uniform(10 - 1))


Thanks. That worked. What does Xcode mean by this:

Type ‘Int’ has no member ‘random’


Your initial code works just fine for me. Are you sure the issue doesn’t happen because of something somewhere else in your code? Because Int most definitely does have a random method.

Oh! I just noticed that you said you were using Xcode 9.4. If you check the documentation page I linked to, you’ll see that Int.random(in:) is available in Xcode 10.0+. That’s your issue right there.

Excellent. Thank you yes. I am seriously just getting started this year and so ill pick up references as I go, so that is super helpful. I appreciate it.