按照几率抽取主观题,最大几率1。
1 /// <summary> 2 /// 判断是否抽到主观题 3 /// </summary> 4 /// <param name="SubjectiveQuestionProbability">抽到主观题的几率</param> 5 /// <returns></returns> 6 public static bool GetProbability(float SubjectiveQuestionProbability) 7 { 8 bool Result = false; 9 double Probability = SubjectiveQuestionProbability; 11 Random rand = new Random(); 12 int oddsCount = 0;//抽中次数,计数器 13 for (int i = 0; i < 1000; i++) 14 { 15 if (rand.Next(1, 1001) <= (int)(Probability * 1000d)) 16 { 17 oddsCount++; 18 } 19 } 20 if (oddsCount / 1000d >= Probability) 21 { 22 Result = true; 23 } 24 return Result;
<script type="text/javascript"> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>