public IActionResult Exam(int paperId) { ExamPaperInfo examPaper = _examPaperApp.Load(paperId); RandomUtil.CanRepeat = true; RandomUtil.RandomCount = (uint)examPaper.QuestionRank; examPaper.Questions = RandomUtil.Draw(examPaper.Questions.ToList()); return(View(examPaper)); }
public void TestDraw() { Dictionary<float, int> dict = new Dictionary<float, int>(){ { 0.2f,1 }, { 0.4f,1 }, { 0.7f,3 }, }; for (int i = 0; i < 100; i++) { float rand = RandomUtil.Draw(dict); System.Console.Out.WriteLine(rand.ToString()); Assert.IsTrue(rand == 0.2f || rand == 0.4f || rand == 0.7f); } }
/// <summary> /// 各ステージでのステップ情報を与えられた条件からランダム生成します。 /// </summary> /// <returns>The step infos.</returns> /// <param name="size">Size.</param> /// <param name="panelNum">Panel number.</param> /// <param name="minFlush">Minimum flush.</param> /// <param name="maxFlush">Max flush.</param> /// <param name="weightedIntervals">Weighted intervals.</param> protected List <StepInfo> CreateStepInfos(int size, int panelNum, float minFlush, float maxFlush, Dictionary <float, int> weightedIntervals) { List <StepInfo> stepInfos = new List <StepInfo>(); float startTime = 0.1f; for (int i = 0; i < size; i++) { float flushTime = RandomUtil.RandomFloat(minFlush, maxFlush); Color color = RandomUtil.RandomColor(); while (color.grayscale < 0.5f) { // 黒っぽい色だと取り直し color = RandomUtil.RandomColor(); } stepInfos.Add(new StepInfo(RandomUtil.DrawNewInt(0, panelNum - 1), color, startTime, flushTime)); startTime += (flushTime + RandomUtil.Draw(weightedIntervals)); } return(stepInfos); }
/// <summary> /// ステージ情報を生成します。 /// </summary> /// <returns>The stage info.</returns> private StageInfo createStageInfo() { int panelSideNum; int stepNum; float limitTime; if (difficultLv == 9) { // Extraモード panelSideNum = 7; stepNum = RandomUtil.RandomInt(8, 9); limitTime = RandomUtil.RandomFloat(12, 15); bool randomReverse = (RandomUtil.RandomInt(0, 4) == 0); int randomSkipN = RandomUtil.Draw(new Dictionary <int, int>() { { 0, 4 }, { 1, 1 }, }); return(new StageInfo(0, currentStageNo + 1, panelSideNum, panelSideNum, limitTime, randomReverse, randomSkipN, CreateStepInfos(stepNum, panelSideNum * panelSideNum, 0.2f, 0.2f, new Dictionary <float, int>() { { 0.2f, 1 }, { 0.3f, 1 } }))); } if (currentStageNo < 10) { panelSideNum = 2 + difficultLv; stepNum = RandomUtil.RandomInt(2, 3) + difficultLv; limitTime = stepNum + 2f; } else if (currentStageNo < 20) { panelSideNum = 3 + difficultLv; stepNum = RandomUtil.RandomInt(2, 3) + difficultLv; limitTime = stepNum + 2f; } else if (currentStageNo < 30) { panelSideNum = 3 + difficultLv; stepNum = RandomUtil.RandomInt(3, 4) + difficultLv; limitTime = stepNum + 1f; } else if (currentStageNo < 40) { panelSideNum = 3 + difficultLv; stepNum = RandomUtil.RandomInt(4, 5) + difficultLv; limitTime = stepNum + 1f; } else if (currentStageNo < 50) { panelSideNum = 4 + difficultLv; stepNum = RandomUtil.RandomInt(4, 5) + difficultLv; limitTime = stepNum; } else if (currentStageNo < 100) { panelSideNum = 4 + difficultLv; stepNum = RandomUtil.RandomInt(6, 7) + difficultLv; limitTime = stepNum - 1f; } else { panelSideNum = 4 + difficultLv; stepNum = RandomUtil.RandomInt(8, 10) + difficultLv; limitTime = stepNum - 1f; } int panelNum = panelSideNum * panelSideNum; return(new StageInfo(0, currentStageNo + 1, panelSideNum, panelSideNum, limitTime, reverse, skipN, CreateStepInfos(stepNum, panelNum, 0.1f, 0.2f, new Dictionary <float, int>() { { 0.2f, 2 }, { 0.3f, 1 }, { 0.4f, 1 }, { 0.5f, 1 }, }))); }