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
This commit is contained in:
Damien Elmes 2022-03-23 21:55:44 +10:00
parent 6735b23e5b
commit bbcab21f13

View File

@ -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);
}
}