---
title: GKRandomDistribution
framework: gameplaykit
role: symbol
role_heading: Class
path: gameplaykit/gkrandomdistribution
---

# GKRandomDistribution

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

## Declaration

```swift
class GKRandomDistribution
```

## Overview

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. You choose the algorithm that randomizes source values for a distribution by initializing it with an instance of any class that implements the GKRandom protocol, such as a basic random source (a subclass of GKRandomSource) or another random distribution. The GKRandomDistribution class itself implements a uniform distribution—for more specialized distributions use one of the subclasses GKGaussianDistribution and GKShuffledDistribution. In a uniform distribution, the probability of generating any number in a specified range (between the values of the distribution’s lowestValue and 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 protocol listed in Generating Random Numbers below. For more information on choosing and using randomizers in GameplayKit, read Randomization in GameplayKit Programming Guide.

## Topics

### Creating a Random Distribution

- [init(randomSource:lowestValue:highestValue:)](gameplaykit/gkrandomdistribution/init(randomsource:lowestvalue:highestvalue:).md)
- [init(lowestValue:highestValue:)](gameplaykit/gkrandomdistribution/init(lowestvalue:highestvalue:).md)

### Creating Specific Random Distributions

- [d6()](gameplaykit/gkrandomdistribution/d6().md)
- [d20()](gameplaykit/gkrandomdistribution/d20().md)
- [init(forDieWithSideCount:)](gameplaykit/gkrandomdistribution/init(fordiewithsidecount:).md)

### Generating Random Numbers

- [nextInt()](gameplaykit/gkrandomdistribution/nextint().md)
- [nextInt(upperBound:)](gameplaykit/gkrandomdistribution/nextint(upperbound:).md)
- [nextUniform()](gameplaykit/gkrandomdistribution/nextuniform().md)
- [nextBool()](gameplaykit/gkrandomdistribution/nextbool().md)

### Working with Characteristics of a Distribution

- [lowestValue](gameplaykit/gkrandomdistribution/lowestvalue.md)
- [highestValue](gameplaykit/gkrandomdistribution/highestvalue.md)
- [numberOfPossibleOutcomes](gameplaykit/gkrandomdistribution/numberofpossibleoutcomes.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Inherited By

- [GKGaussianDistribution](gameplaykit/gkgaussiandistribution.md)
- [GKShuffledDistribution](gameplaykit/gkshuffleddistribution.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [GKRandom](gameplaykit/gkrandom.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Randomization

- [GKRandom](gameplaykit/gkrandom.md)
- [GKRandomSource](gameplaykit/gkrandomsource.md)
- [GKARC4RandomSource](gameplaykit/gkarc4randomsource.md)
- [GKLinearCongruentialRandomSource](gameplaykit/gklinearcongruentialrandomsource.md)
- [GKMersenneTwisterRandomSource](gameplaykit/gkmersennetwisterrandomsource.md)
- [GKGaussianDistribution](gameplaykit/gkgaussiandistribution.md)
- [GKShuffledDistribution](gameplaykit/gkshuffleddistribution.md)
