---
title: "random(probabilityThreshold:seed:)"
framework: foundationmodels
role: symbol
role_heading: Type Method
path: "foundationmodels/generationoptions/samplingmode-swift.struct/random(probabilitythreshold:seed:)"
---

# random(probabilityThreshold:seed:)

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

## Declaration

```swift
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

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 will be 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. note: Sampling modes greedy and random(top:seed:)

## See Also

### Sampling modes

- [greedy](foundationmodels/generationoptions/samplingmode-swift.struct/greedy.md)
- [random(top:seed:)](foundationmodels/generationoptions/samplingmode-swift.struct/random(top:seed:).md)
