templates.random_sources.process_source module
Object that provides randomness from processes.
- class templates.random_sources.process_source.FakeList(items=(None,))[source]
Bases:
List
[Any
]List that completely discards anything you may want to add.
- class templates.random_sources.process_source.ProcessSource(generation_function, amount=0, max_workers=None, debug=False)[source]
Bases:
RandomnessSource
[RR
]Object for providing randomness from processes that repeatedly execute a randomness generating function.
Implements tno.mpc.encryption_schemes.templates._randomness_manager.RandomnessSource.
- __init__(generation_function, amount=0, max_workers=None, debug=False)[source]
Object that starts processes to generate and yield random values.
This construction starts generation workers that generate new randomness using the given generation function. This happens in separate processes to avoid blocking and speed up the generation.
- Parameters:
generation_function (
Callable
[[],TypeVar
(RR
)]) – Unbound callable object (e.g. function or static method) that generates one random value.amount (
int
) – Upper bound on the total amount of randomizations to generate.max_workers (
Optional
[int
]) – Number of workers that generate randomizations in parallel. Should be at least 1. If None, the number of workers equals the number of CPUs on the device.debug (
bool
) – Flag to determine whether debug information should be displayed.
- get_one()[source]
Get one random value.
- Raises:
PauseIteration – All requested randomness was already yielded.
ValueError – No pool of processes instantiated.
- Return type:
TypeVar
(RR
)- Returns:
Single random value.
- increase_requested(amount)[source]
Increase the amount of randomness to be generated by the process pool.
- Parameters:
amount (
int
) – Amount to be generated additionally.- Return type:
None
- property nr_requested: int
Number of random elements requested.
- Returns:
Number of random elements requested.
- property nr_yielded: int
Number of random elements yielded.
- Returns:
Number of random elements yielded.
- property pool: ProcessPoolExecutor
Get the pool of the ProcessSource.
- Raises:
ValueError – No pool has yet been initialized.
- Returns:
Pool of the current object.