<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 10.14.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CreateML",
  "identifier" : "/documentation/CreateML/MLDataTable/randomSample(by:seed:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Create ML"
    ],
    "preciseIdentifier" : "s:8CreateML11MLDataTableV12randomSample2by4seedACSd_SitF"
  },
  "title" : "randomSample(by:seed:)"
}
-->

# randomSample(by:seed:)

Creates a subset of the table by randomly selecting the given proportion
of rows.

```
func randomSample(by proportion: Double, seed: Int = 42) -> MLDataTable
```

## Parameters

`proportion`

The fraction of rows to sample from the original table.
The value must be in the range `(0.0, 1.0)`.

`seed`

A number that seeds a random number generator.

## Return Value

A new data table.

---

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)