Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to specify random number generator for determenism #10

Merged
merged 3 commits into from
Dec 14, 2021

Conversation

Erotemic
Copy link
Contributor

In my application I need the new colors chosen by distinctipy to be deterministic. To accomplish this I simply added a keyword argument rng (for random number generator) to the appropriate functions.

In the default case when rng=None, the global random._inst random state is used. This means that this change is backwards compatible.

More interestingly, the user can either pass an instance of random.Random if they have their own seeded random state, or if they pass a constant value a new random state is created and seeded with that value.

This means I can do:

from distinctipy import distinctipy
distinctipy.get_colors(100, rng=1670706)

and that will return the same colors each time.

@jack89roberts jack89roberts merged commit 2e4112e into alan-turing-institute:master Dec 14, 2021
@jack89roberts
Copy link
Collaborator

Thanks again 🙂

jack89roberts added a commit that referenced this pull request Dec 14, 2021
Main changes:
- #8 - add top level API and refactor setup.py/__init__.py
- #9 - only import pyplot when needed
- #10 - make it possible to set random state
- #11 - ensure constants are floats
- #12 - docs now build from main branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants