<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "GameplayKit",
  "identifier" : "/documentation/GameplayKit/GKRandomDistribution/nextInt(upperBound:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKRandomDistribution(im)nextIntWithUpperBound:"
  },
  "title" : "nextInt(upperBound:)"
}
-->

# nextInt(upperBound:)

Generates and returns a new random integer within the bounds of the distribution and less than the specified limit.

```
func nextInt(upperBound: Int) -> Int
```

## Parameters

`upperBound`

A limit on the values of random numbers to generate.

## Return Value

A new random integer less than the value of the `upperBound` parameter.

## Discussion

Randomly generated integers are in the range specified by the distribution’s [`lowestValue`](/documentation/GameplayKit/GKRandomDistribution/lowestValue) and [`highestValue`](/documentation/GameplayKit/GKRandomDistribution/highestValue) properties (inclusive). The actual upper bound on numbers generated by this method is the lesser of the [`highestValue`](/documentation/GameplayKit/GKRandomDistribution/highestValue) property and the `upperBound` parameter.

When using the [`GKRandomDistribution`](/documentation/GameplayKit/GKRandomDistribution) directly, generated numbers are uniform within this range. Subclasses of [`GKRandomDistribution`](/documentation/GameplayKit/GKRandomDistribution) can alter the relative probability of generating any particular number within the distribution’s range.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)