確率抽出アルゴリズム

3817 ワード

確率に応じて主観問題を抽出し,最大確率は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;