bootstrapSample

fun <T> List<T>.bootstrapSample(n: Int, random: Random = Random): List<T>(source)

Draws a bootstrap sample of n elements with replacement.

Bootstrap sampling randomly picks elements from the list, allowing the same element to be chosen multiple times. This is commonly used for estimating the sampling distribution of a statistic (bootstrap method).

Example:

listOf(1, 2, 3).bootstrapSample(5) // e.g. [2, 1, 3, 1, 2]

Return

a list of n randomly drawn elements, potentially with duplicates.

Parameters

n

the number of elements to draw. Must be non-negative.

random

the random number generator. Defaults to Random.

Type Parameters

T

the type of elements.


fun <T> Iterable<T>.bootstrapSample(n: Int, random: Random = Random): List<T>(source)

Draws a bootstrap sample of n elements with replacement.

This is a convenience overload that accepts any Iterable. The collection is materialized to a list internally.

Return

a list of n randomly drawn elements, potentially with duplicates.

Parameters

n

the number of elements to draw. Must be non-negative.

random

the random number generator. Defaults to Random.

Type Parameters

T

the type of elements.