From bbcab21f13d31a3c1244d5e3234eca9bf226d360 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 23 Mar 2022 21:55:44 +1000 Subject: [PATCH] Start random card position from 1 Anki's DB schema unfortunately uses odid=0 instead of null to indicate a lack of an original due date, so having a due position of 0 leads to the temporary due date not being reset when the card is removed from a filtered deck. https://forums.ankiweb.net/t/anki-2-1-50-beta-6-9-stable-release/18181/52 --- rslib/src/notetype/cardgen.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rslib/src/notetype/cardgen.rs b/rslib/src/notetype/cardgen.rs index 5f99a12f6..cd264dfea 100644 --- a/rslib/src/notetype/cardgen.rs +++ b/rslib/src/notetype/cardgen.rs @@ -345,7 +345,7 @@ impl Collection { fn random_position(highest_position: u32) -> u32 { let mut rng = StdRng::seed_from_u64(highest_position as u64); - rng.gen_range(0..highest_position.max(1000)) + rng.gen_range(1..highest_position.max(1000)) } #[cfg(test)] @@ -355,8 +355,8 @@ mod test { #[test] fn random() { // predictable output and a minimum range of 1000 - assert_eq!(random_position(5), 179); - assert_eq!(random_position(500), 12); + assert_eq!(random_position(5), 180); + assert_eq!(random_position(500), 13); assert_eq!(random_position(5001), 3731); } }