# Swift, how to get a random item from an array

> Learn how to get a random item from an array in Swift using the randomElement() method, which returns an optional Element from your array.

Author: Flavio Copes | Published: 2021-06-15 | Canonical: https://flaviocopes.com/swift-array-random-item/

> This tutorial belongs to the [Swift](https://flaviocopes.com/swift-introduction/) series

Suppose you have an array in Swift, like this:

```swift
let items = [1, 2, 3]
```

and you want to get a random number out of it.

The Array data type provides the `randomElement()` function that returns an `Element?`:

```swift
let item = items.randomElement()
```
