pub struct Generator<R: Rng> { /* private fields */ }
Expand description
A generator randomly generates a full Sudoku, that is, a Sudoku with no missing digits. It uses a random number generator to decide the content. For most cases, sensible defaults are provided by Generator::new_default.
Implementations§
Source§impl Generator<ThreadRng>
impl Generator<ThreadRng>
Sourcepub fn new_default() -> Generator<ThreadRng>
pub fn new_default() -> Generator<ThreadRng>
Creates a new generator that uses a ThreadRng to generate the random digits.
Source§impl<R: Rng> Generator<R>
impl<R: Rng> Generator<R>
Sourcepub fn new(rng: R) -> Generator<R>
pub fn new(rng: R) -> Generator<R>
Creates a new generator that uses the given random number generator to generate random digits.
Sourcepub fn generate<C: Constraint + Clone>(
&mut self,
block_width: usize,
block_height: usize,
constraint: C,
) -> SudokuResult<Sudoku<C>>
pub fn generate<C: Constraint + Clone>( &mut self, block_width: usize, block_height: usize, constraint: C, ) -> SudokuResult<Sudoku<C>>
Generates a new random Sudoku with all digits that matches the given parameters. If it is not possible, an error will be returned.
It is guaranteed that Sudoku::is_valid on the result returns true
.
§Arguments
block_width
: The horizontal dimension of one sub-block of the grid. To ensure a square grid, this is also the number of blocks that compose the grid vertically. For an ordinary Sudoku grid, this is 3. Must be greater than 0.block_height
: The vertical dimension of one sub-block of the grid. To ensure a square grid, this is also the number of blocks that compose the grid horizontally. For an ordinary Sudoku grid, this is 3. Must be greater than 0.constraint
: The constraint which will be matched by the generated Sudoku, which will also be contained and checked by the output Sudoku.
§Errors
SudokuError::InvalidDimensions
Ifblock_width
orblock_height
is invalid (zero).SudokuError::UnsatisfiableConstraint
If there are no grids with the given dimensions that match the providedconstraint
.
Auto Trait Implementations§
impl<R> Freeze for Generator<R>where
R: Freeze,
impl<R> RefUnwindSafe for Generator<R>where
R: RefUnwindSafe,
impl<R> Send for Generator<R>where
R: Send,
impl<R> Sync for Generator<R>where
R: Sync,
impl<R> Unpin for Generator<R>where
R: Unpin,
impl<R> UnwindSafe for Generator<R>where
R: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more