import type { Prng, RandomOptions } from "./_types.js"; export type { Prng, RandomOptions }; /** * Options for {@linkcode sample}. * * @experimental **UNSTABLE**: New API, yet to be vetted. */ export type SampleOptions = RandomOptions & { /** * An array of weights corresponding to each item in the input array. * If supplied, this is used to determine the probability of each item being * selected. */ weights?: ArrayLike; }; /** * Returns a random element from the given array. * * @experimental **UNSTABLE**: New API, yet to be vetted. * * @typeParam T The type of the elements in the array. * @typeParam O The type of the accumulator. * * @param array The array to sample from. * @param options Options modifying the sampling behavior. * * @returns A random element from the given array, or `undefined` if the array * is empty. * * @example Basic usage * ```ts * import { sample } from "@std/random/sample"; * import { assertArrayIncludes } from "@std/assert"; * * const numbers = [1, 2, 3, 4]; * const sampled = sample(numbers); * * assertArrayIncludes(numbers, [sampled]); * ``` * * @example Using `weights` option * ```ts no-assert * import { sample } from "@std/random/sample"; * * const values = ["a", "b", "c"]; * const weights = [5, 3, 2]; * const result = sample(values, { weights }); * // gives "a" 50% of the time, "b" 30% of the time, and "c" 20% of the time * ``` */ export declare function sample(array: ArrayLike, options?: SampleOptions): T | undefined; //# sourceMappingURL=sample.d.ts.map