Generator

Struct Generator 

Source
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>

Source

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>

Source

pub fn new(rng: R) -> Generator<R>

Creates a new generator that uses the given random number generator to generate random digits.

Source

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 If block_width or block_height is invalid (zero).
  • SudokuError::UnsatisfiableConstraint If there are no grids with the given dimensions that match the provided constraint.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V