aleatorpy
Python decorator to control randomness of functions, methods and properties
Science Score: 44.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (7.9%) to scientific vocabulary
Keywords
Repository
Python decorator to control randomness of functions, methods and properties
Basic Info
Statistics
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 0
Topics
Metadata Files
README.md
Controlling randomness
@pseudo_random(*, seed=0, evolutive=True, input_dependent=False, loop=0, make_key=repr)
Decorator Factory to control randomness of decorated function.
The random seed of random and np.random are set depending on the function name, it's input arguments, and the number of time it has been called.
Equality of calls is computed using repr. Inputs with different representations will be considered different.
When called on a class method, it must be decorated with @method decorator included in the package.
The parameters to pseudo_random() are:
- evolutive (bool): random seed is incremented each time the function is called. The counter is different for each set of arguments.
- input_dependent (bool): initial random seed depends on function's input.
- loop (int): get repeating input every loop iteration when evolutive is True. Else, loop argument is ignored.
- make_key: a function to compute the key based on the function name and it's arguments: (f.__name__, args, kwargs). Default is the builtin repr.
Example
Basic usage:
@pseudo_random(input_dependent=input_dependent, evolutive=evolutive)
def get_random_number(*args):
return random.randint(0,9)
argument = '0'
print(" ".join([str(get_random_number(argument)) for _ in range(5)]))
Called 5 times with 5 different inputs will yield: ```
evolutive: True input_dependent: True (5 iterations)
with argument='0': 3 0 4 2 5 with argument='1': 0 7 3 3 4 with argument='2': 8 3 3 4 9 with argument='3': 1 6 8 0 2 with argument='4': 4 0 2 9 1
evolutive: False input_dependent: True (5 iterations)
with argument='0': 3 3 3 3 3 with argument='1': 0 0 0 0 0 with argument='2': 8 8 8 8 8 with argument='3': 1 1 1 1 1 with argument='4': 4 4 4 4 4
evolutive: True input_dependent: False (5 iterations)
with argument='0': 6 2 0 3 3 with argument='1': 6 2 0 3 3 with argument='2': 6 2 0 3 3 with argument='3': 6 2 0 3 3 with argument='4': 6 2 0 3 3
evolutive: False input_dependent: False (5 iterations)
with argument='0': 6 6 6 6 6 with argument='1': 6 6 6 6 6 with argument='2': 6 6 6 6 6 with argument='3': 6 6 6 6 6 with argument='4': 6 6 6 6 6 ```
Citation
If you use this repository, please consider citing my work.
Owner
- Name: Gabriel
- Login: gabriel-vanzandycke
- Kind: user
- Location: Belgium
- Repositories: 8
- Profile: https://github.com/gabriel-vanzandycke
Citation (CITATION.cff)
# YAML 1.2
---
authors:
-
family-names: "Van Zandycke"
given-names: Gabriel
cff-version: "1.1.0"
message: "If you use this software, please cite it using these metadata."
repository-code: "https://github.com/gabriel-vanzandycke/pseudo_random"
title: "Full Control Pseudo Randomness"
version: "0.1"
...
GitHub Events
Total
Last Year
Committers
Last synced: almost 2 years ago
Top Committers
| Name | Commits | |
|---|---|---|
| Gabriel Van Zandycke | g****e@h****m | 11 |
| Gabriel | g****e@k****m | 5 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: over 1 year ago
All Time
- Total issues: 0
- Total pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Total issue authors: 0
- Total pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- numpy *