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)
| 2534 | |
| 2535 | |
| 2536 | def 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 | |
| 2555 | def random_state_data_python( |