[LOW, HIGH] 범위의 Uniform(일양) 분포를 가지는 난수 발생기 (기본은 [0, 1] 범위이다)
Inheritance: RandomizerBase
示例#1
0
        public void DiceProbabilityTest() {
            int success = 0;

            var tryCount = 60000;

            var rnd = new UniformRandomizer(new Interval<double>(1.0, 7.0, IntervalKind.ClosedOpen));
            //(1.0, 6.9999999);

            Parallel.For(1,
                         tryCount,
                         k => {
                             var m = new int[6];
                             var check = 1;

                             for(var i = 0; i < 13; i++) {
                                 int result = (int)rnd.Next() - 1;
                                 m[result]++;
                             }

                             for(var i = 0; i < 6; i++)
                                 if(m[i] == 0) {
                                     check = 0;
                                     break;
                                 }

                             if(check == 1)
                                 Interlocked.Increment(ref success);
                         });

            var prob = (success / (double)tryCount) * 100.0;

            if(IsDebugEnabled)
                log.Debug("Success probability = {0}", prob);
        }
示例#2
0
        public void DiceProbabilityTest()
        {
            int success = 0;

            var tryCount = 60000;

            var rnd = new UniformRandomizer(new Interval <double>(1.0, 7.0, IntervalKind.ClosedOpen));

            //(1.0, 6.9999999);

            Parallel.For(1,
                         tryCount,
                         k => {
                var m     = new int[6];
                var check = 1;

                for (var i = 0; i < 13; i++)
                {
                    int result = (int)rnd.Next() - 1;
                    m[result]++;
                }

                for (var i = 0; i < 6; i++)
                {
                    if (m[i] == 0)
                    {
                        check = 0;
                        break;
                    }
                }

                if (check == 1)
                {
                    Interlocked.Increment(ref success);
                }
            });

            var prob = (success / (double)tryCount) * 100.0;

            if (IsDebugEnabled)
            {
                log.Debug("Success probability = {0}", prob);
            }
        }