Contents

range(_:)

Enforces values fall within a range.

Declaration

static func range(_ range: ClosedRange<Decimal>) -> GenerationGuide<Decimal>

Discussion

Use a range generation guide — whose bounds are inclusive — to ensure the model produces a value that falls within a range. For example, you can specify that the level of characters in your game are between 1 and 100:

@Generable
struct GameCharacter {
    @Guide(description: "A creative name appropriate for a fantasy RPG character")
    var name: String

    @Guide(description: "A level for the character", .range(1...100))
    var level: Int
}