Skip to content

Commit

Permalink
Add seed to _generate_artificial_strings method to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-narozniak committed Mar 8, 2024
1 parent b4203cd commit 6b134d6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion datasets/flwr_datasets/mock_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@


def _generate_artificial_strings(
num_rows: int, num_unique: int, string_length: int
num_rows: int, num_unique: int, string_length: int, seed: int = 42
) -> List[str]:
"""Create list of strings for categories or labels mocking.
Note to keep the seed the same if you reuse this function for in creation of the
dataset for multiple splits.
Parameters
----------
num_rows: int
Expand All @@ -41,12 +44,15 @@ def _generate_artificial_strings(
Number of unique strings that will be initially created.
string_length: int
Length of each string.
seed: int
Seed to the random package.
Returns
-------
string_column : List[str]
List of generated strings.
"""
random.seed(seed)
unique_strings: Set[str] = set()
while len(unique_strings) < num_unique:
random_str = "".join(
Expand Down

0 comments on commit 6b134d6

Please sign in to comment.