Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the StudentsTDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public StudentsTDistribution(RandomSource random)
     : base(random)
 {
     _standardDistribution = new StandardDistribution(RandomSource);
     _chiSquareDistribution = new ChiSquareDistribution(RandomSource);
     SetDistributionParameters(1);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the BetaDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public BetaDistribution(RandomSource random)
     : base(random)
 {
     _gammaAlpha = new GammaDistribution(random);
     _gammaBeta = new GammaDistribution(random);
     SetDistributionParameters(1.0, 1.0);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the FisherSnedecorDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public FisherSnedecorDistribution(RandomSource random)
     : base(random)
 {
     _chiSquaredAlpha = new ChiSquareDistribution(random);
     _chiSquaredBeta = new ChiSquareDistribution(random);
     SetDistributionParameters(1, 1);
 }
Ejemplo n.º 4
0
 public CampaignGenerator(Action<string> logAction)
     : base(logAction)
 {
     databaseProvider = new DatabaseProvider();
     random = new RandomSource();
     memberSearchFilterGenerator = new MemberSearchFilterGenerator();
     campaignRunGenerator = new CampaignRunGenerator(databaseProvider);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ContinuousDistribution"/> class, using the
        /// specified <see cref="RandomSource"/> as underlying random number generator.
        /// </summary>
        /// <param name="random">A <see cref="RandomSource"/> object.</param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
        /// </exception>
        protected ContinuousDistribution(RandomSource random)
        {
            if(random == null)
            {
                throw new ArgumentNullException("random", Properties.LocalStrings.ArgumentNull("generator"));
            }

            _random = random;
        }
        NextInt32()
        {
            double rnd = RandomSource.NextDouble();

            if (rnd >= _cdf[_n - 1])
            {
                return(_last);
            }

            // TODO: consider using binary search instead
            int index = 0;

            while (_cdf[index] < rnd)
            {
                index++;
            }

            return(index + _first);
        }
Ejemplo n.º 7
0
        public Vector <double> RunCalculations(RandomSource random, int iterations, Func <int, double, double> sampleFunction)
        {
            if (random == null)
            {
                throw new ArgumentNullException(nameof(random));
            }
            else if (iterations % ChunkSize != 0)
            {
                throw new ArgumentException($"Iteration count must be a multiple of {ChunkSize}.", nameof(iterations));
            }

            SampleFunction = sampleFunction;

            int numberOfChunks = iterations / ChunkSize;

            results = Vector <double> .Build.Dense(iterations);

            var randomNumberBuffer = new BufferBlock <(int chunkNumber, double[] randomNumbers)>();
            var calculationBlock   = new ActionBlock <(int chunkNumber, double[] randomNumbers)>(DoCalculation, new ExecutionDataflowBlockOptions()
            {
                MaxDegreeOfParallelism = -1
            });

            randomNumberBuffer.LinkTo(calculationBlock, new DataflowLinkOptions()
            {
                PropagateCompletion = true
            });


            for (int i = 0; i < numberOfChunks; i++)
            {
                double[] randomArray = new double[ChunkSize];
                random.NextDoubles(randomArray);
                randomNumberBuffer.Post((i, randomArray));
            }

            randomNumberBuffer.Complete();

            calculationBlock.Completion.Wait();

            return(results);
        }
Ejemplo n.º 8
0
        public void EncodeArray(
            EncodingType encoderType,
            BuiltInType builtInType
            )
        {
            Assume.That(builtInType != BuiltInType.Null);
            int   arrayDimension = RandomSource.NextInt32(99) + 1;
            Array randomData     = DataGenerator.GetRandomArray(builtInType, false, arrayDimension, true);

            string encodeInfo = $"Encoder: {encoderType} Type:{builtInType}";
            Type   type       = TypeInfo.GetSystemType(builtInType, -1);

            TestContext.Out.WriteLine(encodeInfo);
            TestContext.Out.WriteLine("Expected:");
            TestContext.Out.WriteLine(randomData);
            var      encoderStream = new MemoryStream();
            IEncoder encoder       = CreateEncoder(encoderType, Context, encoderStream, type, true, false);

            encoder.WriteArray(builtInType.ToString(), randomData, ValueRanks.OneDimension, builtInType);
            Dispose(encoder);

            var buffer = encoderStream.ToArray();

            switch (encoderType)
            {
            case EncodingType.Json:
                PrettifyAndValidateJson(Encoding.UTF8.GetString(buffer));
                break;
            }
            var      decoderStream = new MemoryStream(buffer);
            IDecoder decoder       = CreateDecoder(encoderType, Context, decoderStream, type);
            object   result        = decoder.ReadArray(builtInType.ToString(), ValueRanks.OneDimension, builtInType);

            Dispose(decoder);

            TestContext.Out.WriteLine("Result:");
            TestContext.Out.WriteLine(result);
            object expected = AdjustExpectedBoundaryValues(encoderType, builtInType, randomData);

            Assert.AreEqual(expected, result, encodeInfo);
            Assert.IsTrue(Opc.Ua.Utils.IsEqual(expected, result), "Opc.Ua.Utils.IsEqual failed to compare expected and result. " + encodeInfo);
        }
Ejemplo n.º 9
0
        public static void NextBytes(byte[] buffer, RandomSource source)
        {
            switch (source)
            {
            case RandomSource.SystemNet:
                SystemNetRandom.GetBytes(buffer);
                break;

            case RandomSource.SodiumCore:
                SodiumCore.GetRandomBytes(new Span <byte>(buffer, 0, buffer.Length));
                break;

            case RandomSource.NSec:
                RandomGenerator.Default.GenerateBytes(buffer);
                break;

            default:
                throw new NotSupportedException();
            }
        }
Ejemplo n.º 10
0
            public SplitConnectionWeightsSearch(
                PopulationParameters populationParameters,
                NetworkParameters networkParameters,
                ReproductionParameters reproductionParameters)
            {
                _populationParameters = populationParameters;
                _neatPopulation       = new Population(networkParameters, reproductionParameters, false);
                _genomes = Range(0, _populationParameters.PopulationSize)
                           .Select(_ => _neatPopulation.CreateInitialGenome());

                _archiveSize = _populationParameters.PopulationSize / 2;
                _archive     = new List <ParetoFrontPoint>(_archiveSize);

                WeightSamples = Range(0, 300)
                                .Select(_ => RandomSource.Range(0, MaxAbsWeightValue))
                                .ToArray();

                InputSamples = Range(0, 60)
                               .Select(_ => RandomSource.Range(0, 1))
                               .ToArray();
            }
Ejemplo n.º 11
0
        public void CoinFlipTest()
        {
            var uut = new RandomSource();

            var iterations     = 1000;
            var coinFlipRatios = new List <double>();

            while (iterations-- > -1)
            {
                var flips = Enumerable.Range(0, 200).Select(_ => uut.CoinFlip()).ToList();
                var ratio = flips.Count(r => r) / (double)flips.Count;
                coinFlipRatios.Add(ratio);
                Assert.True(ratio > 0.3, ratio.ToString("0.00%"));
                Assert.True(ratio < 0.7, ratio.ToString("0.00%"));
            }

            var average = coinFlipRatios.Average();

            Assert.True(average > 0.49, average.ToString("0.00%"));
            Assert.True(average < 0.51, average.ToString("0.00%"));
        }
Ejemplo n.º 12
0
        protected void OneTimeSetUp()
        {
            // work around travis issue by selecting different ports on every run
            int testPort = 50000 + (((Int32)DateTime.UtcNow.ToFileTimeUtc() / 10000) & 0x1fff);

            _serverCapabilities = new ServerCapabilities();
            _randomSource       = new RandomSource(randomStart);
            _dataGenerator      = new DataGenerator(_randomSource);
            _server             = new GlobalDiscoveryTestServer(true);
            _server.StartServer(true, testPort).Wait();

            // load client
            _gdsClient = new GlobalDiscoveryTestClient(true);
            _gdsClient.LoadClientConfiguration(testPort).Wait();

            // good applications test set
            _goodApplicationTestSet    = ApplicationTestSet(goodApplicationsTestCount, false);
            _invalidApplicationTestSet = ApplicationTestSet(invalidApplicationsTestCount, true);

            _goodRegistrationOk      = false;
            _invalidRegistrationOk   = false;
            _goodNewKeyPairRequestOk = false;
        }
Ejemplo n.º 13
0
        public void CheckDisjointsAndEtcAreTakenFromBest()
        {
            // TODO fix crossover, make this one green
            using (var source = RandomSource.DrillIn())
            {
                // Arrange
                var parameters = new NetworkParameters(3, 1)
                {
                    InitialConnectionDensity = 1f
                };
                var tracker =
                    new InnovationTracker(NetworkParameters.BiasCount + parameters.SensorCount + parameters.EffectorCount);

                var best  = new Genome(parameters, tracker, true);
                var worst = new Genome(parameters, tracker, true);
                best.SplitConnection(1);

                // Act
                source.GetParanoid();
                source.PushLimitedNexts(0, 2); // crossover points - all from worst
                source.PushNextBools(true);    // start from best
                var result = best.Mate(worst, CrossoverType.OnePoint);

                // Assert
                Assert.Equal(best.NeatChromosome.Count, result.NeatChromosome.Count);
                for (var i = 0; i < result.NeatChromosome.Count - 2; i++)
                {
                    var parentGene = Assert.Single(worst.NeatChromosome, g => g.Id == result.NeatChromosome[i].Id);
                    Assert.Equal(result.NeatChromosome[i].Weight, parentGene.Weight);
                }
                for (var i = result.NeatChromosome.Count - 2; i < result.NeatChromosome.Count; i++)
                {
                    Assert.Equal(result.NeatChromosome[i].Id, best.NeatChromosome[i].Id);
                    Assert.Equal(result.NeatChromosome[i].Weight, best.NeatChromosome[i].Weight);
                }
            }
        }
Ejemplo n.º 14
0
        // ----------------------------------------------------------------------------------------
        /// <!-- CreateUglyLabel -->
        /// <summary>
        ///      Creates a really ugly letter string including some caps and some spaces
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string CreateUglyLabel(int length)
        {
            Random r   = RandomSource.New().Random;
            string str = "";


            for (int i = 0; i < length; ++i)
            {
                int num;
                switch (r.Next(i + 1))
                {
                case 0: num = r.Next(65, 90); break;

                case 4: num = 32; break;

                case 10: num = 95; break;

                default: num = r.Next(98, 123); break;
                }
                char cha = Convert.ToChar(num);
                str += cha;
            }
            return(str);
        }
Ejemplo n.º 15
0
        protected async Task OneTimeSetUp()
        {
#if DEBUG
            // make sure all servers started in travis use a different port, or test will fail
            const int testPort = 58820;
#else
            const int testPort = 58830;
#endif
            _serverCapabilities = new ServerCapabilities();
            _randomSource       = new RandomSource(randomStart);
            _dataGenerator      = new DataGenerator(_randomSource);
            _server             = new GlobalDiscoveryTestServer(true);
            await _server.StartServer(true, testPort);

            await Task.Delay(1000);

            // load clients
            _gdsClient = new GlobalDiscoveryTestClient(true);
            await _gdsClient.LoadClientConfiguration(testPort);

            _pushClient = new ServerConfigurationPushTestClient(true);
            await _pushClient.LoadClientConfiguration(testPort);

            // connect once
            await _gdsClient.GDSClient.Connect(_gdsClient.GDSClient.EndpointUrl);

            await _pushClient.PushClient.Connect(_pushClient.PushClient.EndpointUrl);

            ConnectGDSClient(true);
            RegisterPushServerApplication(_pushClient.PushClient.EndpointUrl);

            _selfSignedServerCert = new X509Certificate2(_pushClient.PushClient.Session.ConfiguredEndpoint.Description.ServerCertificate);
            _domainNames          = Utils.GetDomainsFromCertficate(_selfSignedServerCert).ToArray();

            CreateCATestCerts(_pushClient.TempStorePath);
        }
 /// <summary>
 /// Initializes a new instance of the CauchyLorentzDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public CauchyLorentzDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(0.0, 1.0);
 }
 /// <summary>
 /// Initializes a new instance of the DiscreteUniformDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public DiscreteUniformDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(0, 1);
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Initializes a new instance, using the specified <see cref="RandomSource"/>
 /// as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public GeometricDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(0.5);
 }
Ejemplo n.º 19
0
 public static void SeedGenerator(int seed)
 {
     Console.WriteLine("Random generator seeded: {0}.", seed);
     generator = new SystemRandomSource(seed);
 }
 /// <summary>
 /// Initializes a new instance of the GeometricDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public GeometricDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(0.5);
 }
 /// <summary>
 /// Initializes a new instance of the ExponentialDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public ExponentialDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(1.0);
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Initializes a new instance, using the specified <see cref="RandomSource"/>
 /// as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public ErlangDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(1, 1.0);
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Initializes a new instance of the TriangularDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public TriangularDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(0.0, 1.0, 0.5);
 }
Ejemplo n.º 24
0
 public RandomSourceRoller([NotNull] RandomSource source)
 {
     _source = source;
 }
 /// <summary>
 /// Initializes a new instance of the LognormalDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public LognormalDistribution(RandomSource random)
     : base(random)
 {
     _standard = new StandardDistribution(random);
     SetDistributionParameters(0.0, 1.0);
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Initializes a new instance of the PoissonDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public PoissonDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(1.0);
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Initializes a new instance of the ChiDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public ChiDistribution(RandomSource random)
     : base(random)
 {
     _standard = new StandardDistribution(random);
     SetDistributionParameters(1);
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Initializes a new instance of the LaplaceDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public LaplaceDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(0.0, 1.0);
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Initializes a new instance of the ZipfDistribution class,
 /// with a default <c>skew</c> equal to <c>2</c>.
 /// </summary>
 public ZipfDistribution()
 {
     _skew = 2d;
     _random = new SystemRandomSource();
 }
Ejemplo n.º 30
0
 BinomialDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(0.5, 1);
 }
 /// <summary>
 /// Initializes a new instance of the StandardDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public StandardDistribution(RandomSource random)
     : base(random)
 {
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Initializes a new instance of the ErlangDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public ErlangDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(1, 1.0);
 }
Ejemplo n.º 33
0
        /// <summary>
        /// Initializes a new instance of the ZipfDistribution class
        /// with the provided skew.
        /// </summary>
        public ZipfDistribution(double skew)
        {
            if(skew <= 1d)
            {
                throw new ArgumentOutOfRangeException("skew", skew, Properties.LocalStrings.ArgumentOutOfRangeGreater("skew", 1));
            }

            _skew = skew;
            _random = new SystemRandomSource();
        }
Ejemplo n.º 34
0
        // ----------------------------------------------------------------------------------------
        /// <!-- SelectionBag -->
        /// <summary>
        ///      Places a bunch of marbles (chars) in a bag for random selection
        /// </summary>
        /// <param name="size">number of marbles in bag (try a multiple of 8 <= 120)</param>
        /// <returns></returns>
        private List <char> SelectionBag(Endeme e, int size)
        {
            Random r = RandomSource.New().Random;

            if (this.Count > this.OriginalCount)
            {
                throw new Exception("SelectionBag");
            }


            // ----------------------------------------------------------------
            //  Define number of each kind of marble (character)
            // ----------------------------------------------------------------
            char[] endeme = e.ToCharArray();
            string str    = "";

            switch (size)
            {
            case 128: str = "@>=;:98765544332221111"; break;

            case 120: str = "@><;987665443322221111"; break;

            case 112: str = "?=;:987654433322211111"; break;

            case 104: str = "><:9876654433222211111"; break;

            case  96: str = "=;:9776544333222111110"; break;

            case  88: str = "<:98765544332221111110"; break;

            case  80: str = ";987665443322221111110"; break;

            case  72: str = ":877654433322211111100"; break;

            case  64: str = "9876544333222111111000"; break;

            case  60: str = "8766544332222111111000"; break;

            case  56: str = "8765543332221111110000"; break;

            case  52: str = "7665443322221111110000"; break;

            case  48: str = "7655433322211111100000"; break;

            case  44: str = "6554433222211111100000"; break;

            case  40: str = "6544333222111111000000"; break;

            case  36: str = "5544332221111110000000"; break;

            case  32: str = "5433322221111110000000"; break;

            case  28: str = "4433222211111100000000"; break;

            case  24: str = "4332222111111000000000"; break;

            case  20: str = "3322221111110000000000"; break;

            case  16: str = "3222111111100000000000"; break;

            case  14: str = "2222111111000000000000"; break;

            case  12: str = "2221111110000000000000"; break;

            case  10: str = "2211111100000000000000"; break;

            case   8: str = "2111111000000000000000"; break;

            case   7: str = "2111110000000000000000"; break;

            case   6: str = "1111110000000000000000"; break;

            case   5: str = "1111100000000000000000"; break;

            case   4: str = "1111000000000000000000"; break;

            case   3: str = "1110000000000000000000"; break;

            case   2: str = "1100000000000000000000"; break;

            case   1: str = "1000000000000000000000"; break;

            default: str = "";
                Dictionary <char, int> cha = new Dictionary <char, int>(22);
                foreach (char c in endeme)
                {
                    cha.Add(c, 0);
                }
                for (int i = 0; i < size; ++i)
                {
                    cha[e.RandomLetter(0.89)]++;
                }
                var query = from ch in cha orderby cha.Values descending select cha;
                str = "";
                foreach (var item in query)
                {
                    str = str + item.ToString();
                }
                break;     // TODO: build the function that approximates these series (.89 * one before)
            }


            // ----------------------------------------------------------------
            //  Put marbles (characters) in bag
            // ----------------------------------------------------------------
            List <int>  quantity = StringToNums(str);
            List <char> bag      = new List <char>(size);

            for (int i = 0; i < quantity.Count; ++i)
            {
                for (int j = 0; j < quantity[i]; ++j)
                {
                    if (i < endeme.Length)
                    {
                        bag.Add(endeme[i]);
                    }
                    else if (endeme.Length > 0)
                    {
                        bag.Add(endeme[0]);
                    }
                }
            }


            return(bag);
        }
 public RandomStringGenerator(RandomSource source = RandomSource.RNGCrypto)
 {
     _source = source;
 }
Ejemplo n.º 36
0
 /// <summary>
 /// Initializes a new instance, using the specified <see cref="RandomSource"/>
 /// as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public PoissonDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(1.0);
 }
Ejemplo n.º 37
0
 public double Sample()
 {
     return(InverseCumulativeDistribution(RandomSource.NextDouble()));
 }
Ejemplo n.º 38
0
 /// <summary>
 /// Initializes a new instance of the ZipfDistribution class
 /// with a default <c>skew</c> equal to <c>2</c>.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 public ZipfDistribution(RandomSource random)
 {
     _skew = 2d;
     _random = random;
 }
Ejemplo n.º 39
0
 /// <summary>
 /// Initializes a new instance of the ArbitraryDistribution class, 
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public ArbitraryDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(0, 1.0);
 }
 GammaDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(1.0, 1.0);
 }
Ejemplo n.º 41
0
 public Endeme RandomEndeme()
 {
     return(RandomEndeme(RandomSource.New().Random));
 }
Ejemplo n.º 42
0
 /// <summary>
 /// Initializes a new instance of the StableDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public StableDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(0.0, 1.0, 1.0, 0.0);
     InitDistributions();
 }
 StandardDistribution(RandomSource random)
     : base(random)
 {
 }
 /// <summary>
 /// Initializes a new instance of the HypergeometricDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public HypergeometricDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(2, 1, 1);
 }
 /// <summary>
 /// Initializes a new instance of the RayleighDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public RayleighDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(1.0);
 }
Ejemplo n.º 46
0
 public static void NextBytes(Span <byte> buffer, RandomSource source)
 {
     NextBytes(buffer, buffer.Length, source);
 }
 TriangularDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(0.0, 1.0, 0.5);
 }
Ejemplo n.º 48
0
 static Util()
 {
     generator = new SystemRandomSource();
 }
 /// <summary>
 /// Initializes a new instance of the ContinuousUniformDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public ContinuousUniformDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(0.0, 1.0);
 }
Ejemplo n.º 50
0
 /// <summary>
 /// Initializes a new instance of the BernoulliDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public BernoulliDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(0.5);
 }
Ejemplo n.º 51
0
 /// <summary>
 /// Ensure tests are reproducible with same seed.
 /// </summary>
 protected void SetRandomSeed(int randomSeed)
 {
     RandomSource  = new RandomSource(randomSeed + RandomStart);
     DataGenerator = new DataGenerator(RandomSource);
 }
Ejemplo n.º 52
0
 /// <summary>
 /// Initializes a new instance of the BinomialDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public BinomialDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(0.5, 1);
 }
        public AbstractArtaProcess CreateArtaProcess(double[] artaCorrelationCoefficients, RandomSource random)
        {
            var fitter = new AutocorrelationFitter(this);
            var arCorrelationCOefficients = fitter.FitArAutocorrelations(artaCorrelationCoefficients, DefaultError);
            var ar = ArProcessFactory.CreateArProcess(artaCorrelationCoefficients, random);

            return(new ArtaProcessGeneral(ar, this));
        }
Ejemplo n.º 54
0
 /// <summary>
 /// Initializes a new instance, using the specified <see cref="RandomSource"/>
 /// as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public BernoulliDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(0.5);
 }
 /// <summary>
 /// Initializes a new instance of the ParetoDistribution class,
 /// using the specified <see cref="RandomSource"/> as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public ParetoDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(1.0, 1.0);
 }
Ejemplo n.º 56
0
 protected void SetUp()
 {
     // ensure tests are reproducible, reset for every test
     RandomSource  = new RandomSource(RandomStart);
     DataGenerator = new DataGenerator(RandomSource);
 }
Ejemplo n.º 57
0
 /// <summary>
 /// Initializes a new instance, using the specified <see cref="RandomSource"/>
 /// as underlying random number generator.
 /// </summary>
 /// <param name="random">A <see cref="RandomSource"/> object.</param>
 /// <exception cref="ArgumentNullException">
 /// <paramref name="random"/> is NULL (<see langword="Nothing"/> in Visual Basic).
 /// </exception>
 public DiscreteUniformDistribution(RandomSource random)
     : base(random)
 {
     SetDistributionParameters(0, 1);
 }