<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Float/random(in:)-6ided",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SBss17FixedWidthInteger14RawSignificandRpzrlE6random2inxSnyxG_tFZ::SYNTHESIZED::s:Sf"
  },
  "title" : "random(in:)"
}
-->

# random(in:)

Returns a random value within the specified range.

```
static func random(in range: Range<Self>) -> Self
```

## Parameters

`range`

The range in which to create a random value.
`range` must be finite and non-empty.

## Return Value

A random value within the bounds of `range`.

## Discussion

Use this method to generate a floating-point value within a specific
range. This example creates three new values in the range
`10.0 ..< 20.0`.

```
for _ in 1...3 {
    print(Double.random(in: 10.0 ..< 20.0))
}
// Prints "18.1900709259179"
// Prints "14.2286325689993"
// Prints "13.1485686260762"
```

The `random()` static method chooses a random value from a continuous
uniform distribution in `range`, and then converts that value to the
nearest representable value in this type. Depending on the size and span
of `range`, some concrete values may be represented more frequently than
others.

This method is equivalent to calling `random(in:using:)`, passing in the
system’s default random generator.

---

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)