dask.bag.random.sample

dask.bag.random.sample(population, k)[source]

Chooses k unique random elements from a bag.

Returns a new bag containing elements from the population while leaving the original population unchanged.

Parameters
population: Bag

Elements to sample.

k: integer, optional

Number of elements to sample.

Examples

>>> import dask.bag as db
>>> from dask.bag import random
>>> b = db.from_sequence(range(5), npartitions=2)
>>> list(random.sample(b, 3).compute())  
[1, 3, 5]