<!--
{
  "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",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKRandomDistribution"
  },
  "title" : "GKRandomDistribution"
}
-->

# GKRandomDistribution

A generator for random numbers that fall within a specific range and that exhibit a specific distribution over multiple samplings.

```
class GKRandomDistribution
```

## Overview> Important:
> The randomization services provided in GameplayKit are suitable for reliably creating deterministic, pseudorandom gameplay mechanics, but are not cryptographically robust. For cryptography, obfuscation, or cipher uses, use the Security framework, described in [Cryptographic Services Guide](https://developer.apple.com/library/archive/documentation/Security/Conceptual/cryptoservices/Introduction/Introduction.html#//apple_ref/doc/uid/TP40011172).

You choose the algorithm that randomizes source values for a distribution by initializing it with an instance of any class that implements the [`GKRandom`](/documentation/GameplayKit/GKRandom) protocol, such as a basic random source (a subclass of [`GKRandomSource`](/documentation/GameplayKit/GKRandomSource)) or another random distribution. The [`GKRandomDistribution`](/documentation/GameplayKit/GKRandomDistribution) class itself implements a uniform distribution—for more specialized distributions use one of the subclasses [`GKGaussianDistribution`](/documentation/GameplayKit/GKGaussianDistribution) and [`GKShuffledDistribution`](/documentation/GameplayKit/GKShuffledDistribution).

In a *uniform* distribution, the probability of generating any number in a specified range (between the values of the distribution’s [`lowestValue`](/documentation/GameplayKit/GKRandomDistribution/lowestValue) and [`highestValue`](/documentation/GameplayKit/GKRandomDistribution/highestValue) properties) is approximately equal. In other words, there is no bias toward any possible outcome. To generate random numbers in this range, use the methods from the [`GKRandom`](/documentation/GameplayKit/GKRandom) protocol listed in Generating Random Numbers below.

For more information on choosing and using randomizers in GameplayKit, read [Randomization](https://developer.apple.com/library/archive/documentation/General/Conceptual/GameplayKit_Guide/RandomSources.html#//apple_ref/doc/uid/TP40015172-CH9) in [GameplayKit Programming Guide](https://developer.apple.com/library/archive/documentation/General/Conceptual/GameplayKit_Guide/index.html#//apple_ref/doc/uid/TP40015172).

## Topics

### Creating a Random Distribution

[`-  initWithRandomSource:lowestValue:highestValue:`](/documentation/GameplayKit/GKRandomDistribution/init(randomSource:lowestValue:highestValue:))

Initializes a uniform random distribution with the specified lower and upper bounds, using the specified source randomizer.

[`+  distributionWithLowestValue:highestValue:`](/documentation/GameplayKit/GKRandomDistribution/init(lowestValue:highestValue:))

Creates a random distribution with the specified lower and upper bounds, using the Arc4 randomizer.

### Creating Specific Random Distributions

[`+  d6`](/documentation/GameplayKit/GKRandomDistribution/d6())

Creates a random distribution equivalent to a six-sided die.

[`+  d20`](/documentation/GameplayKit/GKRandomDistribution/d20())

Creates a random distribution equivalent to a twenty-sided die.

[`+  distributionForDieWithSideCount:`](/documentation/GameplayKit/GKRandomDistribution/init(forDieWithSideCount:))

Creates a random distribution equivalent to a die with the specified number of sides.

### Generating Random Numbers

[`-  nextInt`](/documentation/GameplayKit/GKRandomDistribution/nextInt())

Generates and returns a new random integer within the bounds of the distribution.

[`-  nextIntWithUpperBound:`](/documentation/GameplayKit/GKRandomDistribution/nextInt(upperBound:))

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

[`-  nextUniform`](/documentation/GameplayKit/GKRandomDistribution/nextUniform())

Generates and returns a new random floating-point value within the characteristics of the distribution.

[`-  nextBool`](/documentation/GameplayKit/GKRandomDistribution/nextBool())

Generates and returns a new random Boolean value within the characteristics of the distribution.

### Working with Characteristics of a Distribution

[`lowestValue`](/documentation/GameplayKit/GKRandomDistribution/lowestValue)

The lowest value to be produced by the distribution.

[`highestValue`](/documentation/GameplayKit/GKRandomDistribution/highestValue)

The highest value to be produced by the distribution.

[`numberOfPossibleOutcomes`](/documentation/GameplayKit/GKRandomDistribution/numberOfPossibleOutcomes)

The number of unique values the distribution can generate.

## Relationships

### Inherited By

[`GKGaussianDistribution`](/documentation/GameplayKit/GKGaussianDistribution)

[`GKShuffledDistribution`](/documentation/GameplayKit/GKShuffledDistribution)

### Conforms To

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`GKRandom`](/documentation/GameplayKit/GKRandom)

[`Hashable`](/documentation/Swift/Hashable)

[`Equatable`](/documentation/Swift/Equatable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)