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)
| 2542 | |
| 2543 | |
| 2544 | def 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 | |
| 2563 | def random_state_data_python( |