---
title: "random(in:)"
framework: swift
role: symbol
role_heading: Type Method
path: "swift/int/random(in:)-9mjpw"
---

# random(in:)

Returns a random value within the specified range.

## Declaration

```swift
static func random(in range: Range<Self>) -> Self
```

## Parameters

- `range`: The range in which to create a random value. range must not be empty.

## Return Value

Return Value A random value within the bounds of range.

## Discussion

Discussion Use this method to generate an integer within a specific range. This example creates three new values in the range 1..<100. for _ in 1...3 {     print(Int.random(in: 1..<100)) } // Prints "53" // Prints "64" // Prints "5" This method is equivalent to calling the version that takes a generator, passing in the system’s default random generator.

## See Also

### Creating a Random Integer

- [random(in:using:)](swift/int/random(in:using:)-4lsb5.md)
- [random(in:)](swift/int/random(in:)-8zzqh.md)
- [random(in:using:)](swift/int/random(in:using:)-3dwv4.md)
