diff --git a/sudoku/sudoku.py b/sudoku/sudoku.py index a761979..00d6de7 100644 --- a/sudoku/sudoku.py +++ b/sudoku/sudoku.py @@ -183,7 +183,7 @@ class Sudoku: _empty_cell_value = None # type: None __difficulty = None # type: float - def __init__(self, width = 3, height = None, board = None, difficulty = None, seed = randrange(sys.maxsize)): + def __init__(self, width = 3, height = None, board = None, difficulty = None, seed = None): # type: (int, Optional[int], Optional[Iterable[Iterable[Optional[int]]]], Optional[float], int) -> None """ Initializes a Sudoku board @@ -192,7 +192,7 @@ def __init__(self, width = 3, height = None, board = None, difficulty = None, se :param height: Optional integer representing the height of the Sudoku grid. If not provided, defaults to the value of `width`. :param board: Optional iterable for a the initial state of the Sudoku board. :param difficulty: Optional float representing the difficulty level of the Sudoku puzzle. If provided, sets the difficulty level based on the number of empty cells. Defaults to None. - :param seed: Integer representing the seed for the random number generator used to generate the board. Defaults to a random seed within the system's maximum size. + :param seed: Integer representing the seed for the random number generator used to generate the board. Defaults to a runtime-generated random seed within the system's maximum size. :raises AssertionError: If the width, height, or size of the board is invalid. """ @@ -204,6 +204,10 @@ def __init__(self, width = 3, height = None, board = None, difficulty = None, se assert self.height > 0, 'Height cannot be less than 1' assert self.size > 1, 'Board size cannot be 1 x 1' + if seed is None: + # Generate a fresh random seed every time this is called unless the user explicitly provides it + seed = randrange(sys.maxsize) + if difficulty is not None: self.__difficulty = difficulty @@ -390,7 +394,7 @@ def __str__(self): class DiagonalSudoku(Sudoku): __difficulty = None # type: float - def __init__(self, size = 3, board = None, difficulty = None, seed = randrange(sys.maxsize)): + def __init__(self, size = 3, board = None, difficulty = None, seed = None): # type: (int, Optional[Iterable[Iterable[Optional[int]]]], Optional[float], int) -> None self.width = size self.height = size @@ -403,6 +407,10 @@ def __init__(self, size = 3, board = None, difficulty = None, seed = randrange(s assert self.height > 0, 'Height cannot be less than 1' assert self.size > 1, 'Board size cannot be 1 x 1' + if seed is None: + # Generate a fresh random seed every time this is called unless the user explicitly provides it + seed = randrange(sys.maxsize) + if difficulty is not None: self.__difficulty = difficulty