---
title: "next(upperBound:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/systemrandomnumbergenerator/next(upperbound:)"
---

# next(upperBound:)

Returns a random value that is less than the given upper bound.

## Declaration

```swift
mutating func next<T>(upperBound: T) -> T where T : FixedWidthInteger, T : UnsignedInteger
```

## Parameters

- `upperBound`: The upper bound for the randomly generated value. Must be non-zero.

## Return Value

Return Value A random value of T in the range 0..<upperBound. Every value in the range 0..<upperBound is equally likely to be returned.

## Discussion

Discussion Use this method when you need random binary data to generate another value. If you need an integer value within a specific range, use the static random(in:using:) method on that integer type instead of this method.

## See Also

### Generating Random Binary Data

- [next()](swift/systemrandomnumbergenerator/next().md)
- [next()](swift/systemrandomnumbergenerator/next()-2x0ly.md)
