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)
| 2530 | |
| 2531 | |
| 2532 | def 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 | |
| 2551 | def random_state_data_python( |