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

Function random_sample

dask/bag/core.py:2536–2552  ·  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

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

Callers

nothing calls this directly

Calls 2

RandomClass · 0.90
randomMethod · 0.45

Tested by

no test coverage detected