<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "GameplayKit",
  "identifier" : "/documentation/GameplayKit/GKStrategist/randomSource",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(pl)GKStrategist(py)randomSource"
  },
  "title" : "randomSource"
}
-->

# randomSource

A randomizer object to be used when the strategist randomly selects a move.

```
var randomSource: (any GKRandom)? { get set }
```

## Discussion

A strategist class uses this random source when you call the [`bestMoveForActivePlayer()`](/documentation/GameplayKit/GKStrategist/bestMoveForActivePlayer()) method. Different strategist classes use randomization in different ways:

- A *deterministic* strategy, such as that of the [`GKMinmaxStrategist`](/documentation/GameplayKit/GKMinmaxStrategist) class, can reach states where multiple moves are rated the most desirable. In such cases, the strategist can randomly choose from among the best possible moves, making the behavior of a computer-controlled player appear more natural and unpredictable.

If this property is set to `nil` (the default), the [`GKMinmaxStrategist`](/documentation/GameplayKit/GKMinmaxStrategist) class method does not randomize—that is, when repeatedly presented with the same set of equally-optimal moves, the [`bestMoveForActivePlayer()`](/documentation/GameplayKit/GKStrategist/bestMoveForActivePlayer()) method always makes the same choice.

- A *probabilistic* strategy, such as that of the [`GKMonteCarloStrategist`](/documentation/GameplayKit/GKMonteCarloStrategist) class, *requires* a random source in order to randomly explore the set of possible moves.

If this property is set to `nil` (the default), the [`GKMonteCarloStrategist`](/documentation/GameplayKit/GKMonteCarloStrategist) class throws an exception when you call the [`bestMoveForActivePlayer()`](/documentation/GameplayKit/GKStrategist/bestMoveForActivePlayer()) method.

A randomizer is any object that implements the [`GKRandom`](/documentation/GameplayKit/GKRandom) protocol, such as the [`GKRandomSource`](/documentation/GameplayKit/GKRandomSource) and [`GKRandomDistribution`](/documentation/GameplayKit/GKRandomDistribution) classes and their subclasses. Choosing a separate randomizer instance from that used by other systems in your game ensures that the randomization of moves is independent; that is, the strategist’s selection of moves does not depend on your game’s other uses of randomization APIs. You can also use randomizer classes to reproduce a specific sequence of random actions for debugging, and to fine-tune the randomization behavior.

---

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)