mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 00:12:25 -04:00
Increase randomness in random sorting of new cards
Currently, the new cards appear roughly in the same order on consecutive days (if they are skipped by burying). This change aims to increase randomness by spreading out the salt across the hash space.
This commit is contained in:
parent
3d0a408a2b
commit
e218f64b3b
1 changed files with 10 additions and 3 deletions
|
@ -61,13 +61,14 @@ impl QueueBuilder {
|
|||
}
|
||||
|
||||
fn gather_new_cards(&mut self, col: &mut Collection) -> Result<()> {
|
||||
let salt = knuth_salt(self.context.timing.days_elapsed);
|
||||
match self.context.sort_options.new_gather_priority {
|
||||
NewCardGatherPriority::Deck => {
|
||||
self.gather_new_cards_by_deck(col, NewCardSorting::LowestPosition)
|
||||
}
|
||||
NewCardGatherPriority::DeckThenRandomNotes => self.gather_new_cards_by_deck(
|
||||
col,
|
||||
NewCardSorting::RandomNotes(self.context.timing.days_elapsed),
|
||||
NewCardSorting::RandomNotes(salt),
|
||||
),
|
||||
NewCardGatherPriority::LowestPosition => {
|
||||
self.gather_new_cards_sorted(col, NewCardSorting::LowestPosition)
|
||||
|
@ -77,11 +78,11 @@ impl QueueBuilder {
|
|||
}
|
||||
NewCardGatherPriority::RandomNotes => self.gather_new_cards_sorted(
|
||||
col,
|
||||
NewCardSorting::RandomNotes(self.context.timing.days_elapsed),
|
||||
NewCardSorting::RandomNotes(salt),
|
||||
),
|
||||
NewCardGatherPriority::RandomCards => self.gather_new_cards_sorted(
|
||||
col,
|
||||
NewCardSorting::RandomCards(self.context.timing.days_elapsed),
|
||||
NewCardSorting::RandomCards(salt),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
@ -169,4 +170,10 @@ impl QueueBuilder {
|
|||
true
|
||||
}
|
||||
}
|
||||
|
||||
// Generates a salt for use with fnvhash. Useful to increase randomness
|
||||
// when the base salt is a small integer.
|
||||
fn knuth_salt(base_salt: u32) -> u32 {
|
||||
base_salt.wrapping_mul(2654435761)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue