MCPcopy Create free account
hub / github.com/dask/dask / random_sample

Function random_sample

dask/bag/core.py:2532–2548  ·  view source on GitHub ↗

Filter elements of `x` by a probability `prob`. Parameters ---------- x : iterable state_data : tuple A tuple that can be passed to ``random.Random.setstate``. prob : float A float between 0 and 1, representing the probability that each element will be yi

(x, state_data, prob)

Source from the content-addressed store, hash-verified

2530
2531
2532def random_sample(x, state_data, prob):
2533 """Filter elements of `x` by a probability `prob`.
2534
2535 Parameters
2536 ----------
2537 x : iterable
2538 state_data : tuple
2539 A tuple that can be passed to ``random.Random.setstate``.
2540 prob : float
2541 A float between 0 and 1, representing the probability that each
2542 element will be yielded.
2543 """
2544 random_state = Random()
2545 random_state.setstate(state_data)
2546 for i in x:
2547 if random_state.random() < prob:
2548 yield i
2549
2550
2551def random_state_data_python(

Callers

nothing calls this directly

Calls 2

RandomClass · 0.90
randomMethod · 0.45

Tested by

no test coverage detected