Class

# GKRandomDistribution

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

## Overview

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.

## Symbols

### Creating a Random Distribution

`init(randomSource: GKRandom, lowestValue: Int, highestValue: Int)`

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

`init(lowestValue: Int, highestValue: Int)`

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

### Creating Specific Random Distributions

`class func d6()`

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

`class func d20()`

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

`init(forDieWithSideCount: Int)`

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

### Generating Random Numbers

`func nextInt()`

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

`func nextInt(upperBound: Int)`

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

`func nextUniform()`

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

`func nextBool()`

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

### Working with Characteristics of a Distribution

`var lowestValue: Int`

The lowest value to be produced by the distribution.

`var highestValue: Int`

The highest value to be produced by the distribution.

`var numberOfPossibleOutcomes: Int`

The number of unique values the distribution can generate.