# Module: sample

Returns one or more items of an array picked at random.

# Functions

# sample

sampleT›(elements: T[], size: number): T[]

Defined in src/sample.ts:38

Returns n random elements from an array.

import { sample } from 'utilist';

sample([1, 2, 3, 4, 5], 2); // returns an array with two random elements from 1 to 5.

Type parameters:

T

Parameters:

Name Type Default Description
elements T[] - The array to get a random element from.
size number 1 The amount of elements to pick. Defaults to 1.

Returns: T[]


# sampleOne

sampleOneT›(elements: T[]): T

Defined in src/sample.ts:22

Returns a random element from an array.

import { sampleOne } from 'utilist';

sampleOne([1, 2, 3, 4, 5]); // returns a random element from 1 to 5.

Type parameters:

T

Parameters:

Name Type Description
elements T[] The array to get a random element from.

Returns: T