Next() публичный Метод

난수 발생
public Next ( ) : double
Результат double
Пример #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);
            }
        }