-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #340 from OHBA-analysis/randomseed
Randomseed
- Loading branch information
Showing
5 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Miscellaneous utility classes and functions. | ||
""" | ||
|
||
import logging | ||
import random | ||
import numpy as np | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def set_random_seed(seed=None): | ||
"""Set all random seeds. | ||
This includes Python's random module and NumPy. | ||
Parameters | ||
---------- | ||
seed : int | ||
Random seed. | ||
""" | ||
if seed is None: | ||
seed = random.randint(0, 2**32 - 1) | ||
|
||
logger.info(f"Setting random seed to {seed}") | ||
|
||
random.seed(seed) | ||
np.random.seed(seed) | ||
return seed |