---
title: "random(using:)"
framework: swift
role: symbol
role_heading: Type Method
path: "swift/bool/random(using:)"
---

# random(using:)

Returns a random Boolean value, using the given generator as a source for randomness.

## Declaration

```swift
static func random<T>(using generator: inout T) -> Bool where T : RandomNumberGenerator
```

## Parameters

- `generator`: The random number generator to use when creating the new random value.

## Return Value

Return Value Either true or false, randomly chosen with equal probability.

## Discussion

Discussion This method returns true and false with equal probability. Use this method to generate a random Boolean value when you are using a custom random number generator. let flippedHeads = Bool.random(using: &myGenerator) if flippedHeads {     print("Heads, you win!") } else {     print("Maybe another try?") } note: The algorithm used to create random values may change in a future version of Swift. If you’re passing a generator that results in the same sequence of Boolean values each time you run your program, that sequence may change when your program is compiled using a different version of Swift.

## See Also

### Creating a Random Value

- [random()](swift/bool/random().md)
