---
title: GKMersenneTwisterRandomSource
framework: gameplaykit
role: symbol
role_heading: Class
path: gameplaykit/gkmersennetwisterrandomsource
---

# GKMersenneTwisterRandomSource

A basic random number generator implementing the Mersenne Twister algorithm, which is more random, but slower than the default random source.

## Declaration

```swift
class GKMersenneTwisterRandomSource
```

## 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. To generate basic random values with this random source, use the methods defined in the GKRandom protocol. To generate random values with a specific range and distribution, use this random source with the GKRandomDistribution class or one of its subclasses. When you create an instance of this class, the resulting random source is both independent and deterministic—that is, the sequence of numbers generated by one instance has no effect on the sequence generated by any other instance, and that sequence can be replicated when necessary. For details on replicating sequences, see the seed property and init(seed:) initializer. The Mersenne Twister random source uses a common 64-bit variant of the algorithm originally described by Matsumoto and Nishimura in 2000, based on the Mersenne prime power 19937. This random source is therefore compatible with other implementations of that algorithm, including the mt19937_64 type from the std::mersenne_twister_engine template in C++11. That is, if you initialize a GKMersenneTwisterRandomSource instance and a compatible implementation using the same seed value, both generate the same sequence of numbers. For more information on choosing and using randomizers in GameplayKit, read Randomization in GameplayKit Programming Guide.

## Topics

### Creating a Random Source

- [init()](gameplaykit/gkmersennetwisterrandomsource/init().md)
- [init(seed:)](gameplaykit/gkmersennetwisterrandomsource/init(seed:).md)

### Replicating Random Behavior

- [seed](gameplaykit/gkmersennetwisterrandomsource/seed.md)

## Relationships

### Inherits From

- [GKRandomSource](gameplaykit/gkrandomsource.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)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)

## See Also

### Randomization

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