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

# random(top:seed:)

A sampling mode that considers a fixed number of high-probability tokens.

## Declaration

```swift
static func random(top k: Int, seed: UInt64? = nil) -> GenerationOptions.SamplingMode
```

## Parameters

- `k`: The number of tokens to consider.
- `seed`: An optional random seed used to make output more deterministic.

## Discussion

Discussion Also known as top-k. During the token-selection process, the vocabulary is sorted by probability a token is selected from among the top K candidates. Smaller values of K will ensure only the most probable tokens are candidates for selection, resulting in more deterministic and confident answers. Larger values of K will allow less probably tokens to be selected, raising non-determinism and creativity. note: Setting a random seed is not guaranteed to result in fully deterministic output. It is best effort. note: Sampling modes greedy and random(probabilityThreshold:seed:)

## See Also

### Sampling modes

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