From 2a4911799578013a5fe547af117eb5f6abd2899b Mon Sep 17 00:00:00 2001 From: BOT Alex <44818698+MagicBOTAlex@users.noreply.github.com> Date: Thu, 29 Jun 2023 13:13:04 +0200 Subject: [PATCH] Now it doesn't show the same CChar pinyin in selection --- LearningChineseFixed/Pages/Learn.razor | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/LearningChineseFixed/Pages/Learn.razor b/LearningChineseFixed/Pages/Learn.razor index 1b9584d..9854df0 100644 --- a/LearningChineseFixed/Pages/Learn.razor +++ b/LearningChineseFixed/Pages/Learn.razor @@ -125,14 +125,20 @@ void GenerateQuestion() { - if (DontSkipTheseCChar.Count < 3) throw new Exception("Finished this chunk of CChars"); + if (DontSkipTheseCChar.Count < 5) throw new Exception("Finished this chunk of CChars"); int correctIndex = Random.Shared.Next(0, Answers.Length); for (int i = 0; i < Answers.Length; i++) { bool isCorrect = i == correctIndex; - Answers[i] = new Answer(DontSkipTheseCChar[Random.Shared.Next(0, DontSkipTheseCChar.Count)], isCorrect); + CChar randomCChar; + + repickRandomCChar: + randomCChar = DontSkipTheseCChar[Random.Shared.Next(0, DontSkipTheseCChar.Count)]; + if (Answers.Any(x =>x != null && x.cchar == randomCChar)) goto repickRandomCChar; + + Answers[i] = new Answer(randomCChar, isCorrect); } }