MCPcopy
hub / github.com/dask/dask / random_sample

Function random_sample

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

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

Callers

nothing calls this directly

Calls 2

RandomClass · 0.90
randomMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…