<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Sequence/randomSplit(by:using:)-500fy",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:ST18CreateMLComponentsE11randomSplit2by5usings10ArraySliceVyqd__G_AGtSd_qd_0_zt7ElementQzRsd__SGRd_0_r0_lF"
  },
  "title" : "randomSplit(by:using:)"
}
-->

# randomSplit(by:using:)

Generates two generic arrays by randomly splitting the elements of the sequence.

```
func randomSplit<T, Generator>(by proportion: Double, using generator: inout Generator) -> (ArraySlice<T>, ArraySlice<T>) where T == Self.Element, Generator : RandomNumberGenerator
```

## Parameters

`proportion`

A proportion in the range `[0.0, 1.0]`.

`generator`

A random-number generator.

## Return Value

A tuple of array slices.

---

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)