<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -",
    "macCatalyst: 26.0.0 -",
    "macOS: 26.0.0 -",
    "visionOS: 26.0.0 -",
    "watchOS: 27.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "FoundationModels",
  "identifier" : "/documentation/FoundationModels/GenerationOptions/SamplingMode-swift.struct/random(probabilityThreshold:seed:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation Models",
      "FoundationModels"
    ],
    "preciseIdentifier" : "s:16FoundationModels17GenerationOptionsV12SamplingModeV6random20probabilityThreshold4seedAESd_s6UInt64VSgtFZ"
  },
  "title" : "random(probabilityThreshold:seed:)"
}
-->

# random(probabilityThreshold:seed:)

A mode that considers a variable number of high-probability tokens
based on the specified threshold.

```
static func random(probabilityThreshold: Double, seed: UInt64? = nil) -> GenerationOptions.SamplingMode
```

## Parameters

`probabilityThreshold`

A number between `0.0` and `1.0` that
increases sampling pool size.

`seed`

An optional random seed used to make output more deterministic.

## Discussion

Also known as top-p or nucleus sampling.

With nucleus sampling, tokens are sorted by probability and added to a
pool of candidates until the cumulative probability of the pool exceeds
the specified threshold, and then a token is sampled from the pool.

Because the number of tokens isn’t predetermined, the selection pool size
is larger when the distribution is flat and smaller when it is spikey.
This variability can lead to a wider variety of options to choose from, and
potentially more creative responses.

> Note: Setting a random seed is not guaranteed to result in fully deterministic
> output. It is best effort.

> SeeAlso: Sampling modes ``doc://com.apple.foundationmodels/documentation/FoundationModels/GenerationOptions/SamplingMode-swift.struct/greedy`` and ``doc://com.apple.foundationmodels/documentation/FoundationModels/GenerationOptions/SamplingMode-swift.struct/random(top:seed:)``

---

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)