<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "GameplayKit",
  "identifier" : "/documentation/GameplayKit/GKRandomSource/arrayByShufflingObjects(in:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "GameplayKit"
    ],
    "preciseIdentifier" : "c:objc(cs)GKRandomSource(im)arrayByShufflingObjectsInArray:"
  },
  "title" : "arrayByShufflingObjects(in:)"
}
-->

# arrayByShufflingObjects(in:)

Returns an array whose contents are the same as those of the specified array, but in a random order determined by the random source.

```
func arrayByShufflingObjects(in array: [Any]) -> [Any]
```

## Parameters

`array`

An array of objects.

## Return Value

An array whose contents have been randomly shuffled.

## Discussion

Use this method with an instance of [`GKRandomSource`](/documentation/GameplayKit/GKRandomSource) (or of one of its subclasses) to randomly rearrange the contents of an array. For example, in a card game you might use this method to randomize an array of card objects.

---

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)