Skip to main content

oneOfWeighted

Callable

  • oneOfWeighted<T>(...arbitraries: [...T[]]): Dependent<ReturnType<[...T][number][1][value]>[value]>

  • It generates an integer between 0 and the number of arbitraries passed in, and then generates a weighted value from the corresponding arbitrary.

    Example

    random(oneOf([2, object({foo: string()})], [1, object({bar: string()})]))
    // => {foo: "bar"}

    random(oneOf([2, object({foo: string()})], [1, object({bar: string()})]))
    // => {foo: "bar"}

    random(oneOf([2, object({foo: string()})], [1, object({bar: string()})]))
    // => {bar: "foo"}

    Type parameters

    Parameters

    • rest...arbitraries: [...T[]]

      The arbitraries to select one of.

    Returns Dependent<ReturnType<[...T][number][1][value]>[value]>

    An arbitrary that is randomly chosen from the weighted list.