<!--
{
  "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/GenerationGuide/range(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation Models",
      "FoundationModels"
    ],
    "preciseIdentifier" : "s:16FoundationModels15GenerationGuideVAASo9NSDecimalaRszlE5rangeyACyAEGSNyAEGFZ::OverloadGroup"
  },
  "title" : "range(_:)"
}
-->

# range(_:)

Enforces values that fall within a range.

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

## Discussion

Bounds are inclusive.

A `range` generation guide may be used when you want to ensure the model
produces a value that falls in some range, such as the cost for an item
in a game.

```swift
@Generable
struct ShopItem {
    @Guide(description: "A creative name for an item sold in a fantasy RPG")
    var name: String

    @Guide(description: "A cost for the item", .range(0.25...1000))
    var cost: Decimal
}
```

---

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)