dask.bag.Bag.random_sample

dask.bag.Bag.random_sample

Bag.random_sample(prob, random_state=None)[source]

Return elements from bag with probability of prob.

Parameters
probfloat

A float between 0 and 1, representing the probability that each element will be returned.

random_stateint or random.Random, optional

If an integer, will be used to seed a new random.Random object. If provided, results in deterministic sampling.

Examples

>>> import dask.bag as db
>>> b = db.from_sequence(range(10))
>>> b.random_sample(0.5, 43).compute()
[0, 1, 3, 4, 7, 9]
>>> b.random_sample(0.5, 43).compute()
[0, 1, 3, 4, 7, 9]