예제 #1
0
 public List <Pool> Create(List <Pool> pools, int numOfTeams, SeedMethod seedMethod)
 {
     _numOfTeams = numOfTeams;
     _seedMethod = seedMethod;
     pools       = CreateEmptyTeamLists(pools);
     pools       = PopulateTeamLists(pools);
     pools       = NameTeams(pools);
     return(pools);
 }
        /// <summary>
        /// Migrate and seed the DbContext using the seed delegate.
        /// </summary>
        /// <typeparam name="TContext">The DbContext type</typeparam>
        /// <param name="host">The host that will execute the migration.</param>
        /// <param name="seeder">The seed delegate.</param>
        /// <returns>A task that represents the asynchronous migration operation.</returns>
        public static Task <IHost> MigrateDbContext <TContext>(this IHost host, SeedMethod <TContext> seeder)
            where TContext : DbContext
        {
            Task asyncSeeder(TContext c, IServiceProvider s)
            {
                seeder(c, s);
                return(Task.CompletedTask);
            }

            return(host.MigrateDbContext <TContext>(asyncSeeder));
        }
#pragma warning disable
        /// <summary>
        /// Generates an array of generated numbers with the provided output size.
        /// if SeedMethod is SeedMethod.InitGenRand, the seed parameter must also be provided.
        /// if SeedMethod is SeedMethod.InitByArray, the seeds parameter must also be provided.
        /// </summary>
        /// <remarks>
        /// This code in this method is taken from the c code published by the authors of the mersenne twister.
        /// It is edited as little as possible, (just enough to make it work in c#). Hence the warning disable pragma
        /// It is intended to test the c# implementation of the generator.
        /// </remarks>
        private static uint[] Original(
            int outputSize,
            ulong seed        = default,
            ulong[] seeds     = default,
            SeedMethod method = default)
        {
            /*
             * A C-program for MT19937, with initialization improved 2002/1/26.
             * Coded by Takuji Nishimura and Makoto Matsumoto.
             *
             * Before using, initialize the state by using init_genrand(seed)
             * or init_by_array(init_key, key_length).
             *
             * Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
             * All rights reserved.
             *
             * Redistribution and use in source and binary forms, with or without
             * modification, are permitted provided that the following conditions
             * are met:
             *
             *   1. Redistributions of source code must retain the above copyright
             *      notice, this list of conditions and the following disclaimer.
             *
             *   2. Redistributions in binary form must reproduce the above copyright
             *      notice, this list of conditions and the following disclaimer in the
             *      documentation and/or other materials provided with the distribution.
             *
             *   3. The names of its contributors may not be used to endorse or promote
             *      products derived from this software without specific prior written
             *      permission.
             *
             * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
             * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
             * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
             * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
             * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
             * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
             * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
             * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
             * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
             * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
             * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
             *
             *
             * Any feedback is very welcome.
             * http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
             * email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
             */

            /* Period parameters */
            const int   N          = 624;
            const int   M          = 397;
            const ulong MATRIX_A   = 0x9908b0dfUL; /* constant vector a */
            const ulong UPPER_MASK = 0x80000000UL; /* most significant w-r bits */
            const ulong LOWER_MASK = 0x7fffffffUL; /* least significant r bits */

            var mt  = new ulong [N];               /* the array for the state vector  */
            var mti = N + 1;                       /* mti==N+1 means mt[N] is not initialized */

            /* initializes mt[N] with a seed */
            void init_genrand(ulong s)
            {
                mt[0] = s & 0xffffffffUL;
                for (mti = 1; mti < N; mti++)
                {
                    mt[mti] =
                        1812433253UL * (mt[mti - 1] ^ (mt[mti - 1] >> 30)) + (ulong)mti;
                    /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
                    /* In the previous versions, MSBs of the seed affect   */
                    /* only MSBs of the array mt[].                        */
                    /* 2002/01/09 modified by Makoto Matsumoto             */
                    mt[mti] &= 0xffffffffUL;
                    /* for >32 bit machines */
                }
            }

            /* initialize by an array with array-length */
            /* init_key is the array for initializing keys */
            /* key_length is its length */
            /* slight change for C++, 2004/2/26 */
            void init_by_array(ulong[] init_key)
            {
                var key_length = init_key.Length;
                int i, j, k;

                init_genrand(19650218UL);
                i = 1;
                j = 0;
                k = N > key_length ? N : key_length;
                for (; k != 0; k--)
                {
                    mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1664525UL))
                            + init_key[j] + (ulong)j; /* non linear */
                    mt[i] &= 0xffffffffUL;            /* for WORDSIZE > 32 machines */
                    i++;
                    j++;
                    if (i >= N)
                    {
                        mt[0] = mt[N - 1];
                        i     = 1;
                    }

                    if (j >= key_length)
                    {
                        j = 0;
                    }
                }

                for (k = N - 1; k != 0; k--)
                {
                    mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 30)) * 1566083941UL))
                            - (ulong)i;    /* non linear */
                    mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
                    i++;
                    if (i >= N)
                    {
                        mt[0] = mt[N - 1];
                        i     = 1;
                    }
                }

                mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
            }

            /* generates a random number on [0,0xffffffff]-interval */
            ulong genrand_int32()
            {
                ulong y;
                var   mag01 = new ulong[2] {
                    0x0UL, MATRIX_A
                };

                /* mag01[x] = x * MATRIX_A  for x=0,1 */

                if (mti >= N)
                {
                    /* generate N words at one time */
                    int kk;

                    if (mti == N + 1)         /* if init_genrand() has not been called, */
                    {
                        init_genrand(5489UL); /* a default initial seed is used */
                    }
                    for (kk = 0; kk < N - M; kk++)
                    {
                        y      = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
                        mt[kk] = mt[kk + M] ^ (y >> 1) ^ mag01[y & 0x1UL];
                    }

                    for (; kk < N - 1; kk++)
                    {
                        y      = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
                        mt[kk] = mt[kk + (M - N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
                    }

                    y         = (mt[N - 1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
                    mt[N - 1] = mt[M - 1] ^ (y >> 1) ^ mag01[y & 0x1UL];

                    mti = 0;
                }

                y = mt[mti++];

                /* Tempering */
                y ^= y >> 11;
                y ^= (y << 7) & 0x9d2c5680UL;
                y ^= (y << 15) & 0xefc60000UL;
                y ^= y >> 18;

                return(y);
            }

            switch (method)
            {
            case SeedMethod.InitGenRand:
                init_genrand(seed);
                break;

            case SeedMethod.InitByArray:
                init_by_array(seeds);
                break;
            }

            var result = new uint[outputSize];

            for (var i = 0; i < result.Length; ++i)
            {
                result[i] = (uint)genrand_int32();
            }

            return(result);
        }
#pragma warning disable
        /// <summary>
        /// Generates an array of generated numbers with the provided output size.
        /// if SeedMethod is SeedMethod.InitGenRand, the seed parameter must also be provided.
        /// if SeedMethod is SeedMethod.InitByArray, the seeds parameter must also be provided.
        /// </summary>
        /// <remarks>
        /// This code in this method is taken from the c code published by the authors of the mersenne twister.
        /// It is edited as little as possible, (just enough to make it work in c#). Hence the warning disable pragma
        /// It is intended to test the c# implementation of the generator.
        /// </remarks>
        private static ulong[] Original(
            int outputSize,
            ulong seed        = default,
            ulong[] seeds     = default,
            SeedMethod method = default)
        {
            /*
             * A C-program for MT19937-64 (2004/9/29 version).
             * Coded by Takuji Nishimura and Makoto Matsumoto.
             *
             * This is a 64-bit version of Mersenne Twister pseudorandom number
             * generator.
             *
             * Before using, initialize the state by using init_genrand64(seed)
             * or init_by_array64(init_key, key_length).
             *
             * Copyright (C) 2004, Makoto Matsumoto and Takuji Nishimura,
             * All rights reserved.
             *
             * Redistribution and use in source and binary forms, with or without
             * modification, are permitted provided that the following conditions
             * are met:
             *
             *   1. Redistributions of source code must retain the above copyright
             *       notice, this list of conditions and the following disclaimer.
             *
             *   2. Redistributions in binary form must reproduce the above copyright
             *       notice, this list of conditions and the following disclaimer in the
             *       documentation and/or other materials provided with the distribution.
             *
             *   3. The names of its contributors may not be used to endorse or promote
             *       products derived from this software without specific prior written
             *       permission.
             *
             * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
             * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
             * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
             * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
             * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
             * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
             * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
             * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
             * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
             * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
             * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
             *
             * References:
             * T. Nishimura, ``Tables of 64-bit Mersenne Twisters''
             *   ACM Transactions on Modeling and
             *   Computer Simulation 10. (2000) 348--357.
             * M. Matsumoto and T. Nishimura,
             *   ``Mersenne Twister: a 623-dimensionally equidistributed
             *   uniform pseudorandom number generator''
             *   ACM Transactions on Modeling and
             *   Computer Simulation 8. (Jan. 1998) 3--30.
             *
             * Any feedback is very welcome.
             * http://www.math.hiroshima-u.ac.jp/~m-mat/MT/emt.html
             * email: m-mat @ math.sci.hiroshima-u.ac.jp (remove spaces) */

            const int   NN       = 312;
            const int   MM       = 156;
            const ulong MATRIX_A = 0xB5026F5AA96619E9UL;
            const ulong UM       = 0xFFFFFFFF80000000UL; /* Most significant 33 bits */
            const ulong LM       = 0x7FFFFFFFUL;         /* Least significant 31 bits */

            /* The array for the state vector */
            var mt = new ulong[NN];

            /* mti==NN+1 means mt[NN] is not initialized */
            ulong mti = NN + 1;

            /* initializes mt[NN] with a seed */
            void init_genrand64(ulong seed)
            {
                mt[0] = seed;
                for (mti = 1; mti < NN; mti++)
                {
                    mt[mti] = 6364136223846793005UL * (mt[mti - 1] ^ (mt[mti - 1] >> 62)) + mti;
                }
            }

            /* initialize by an array with array-length */
            /* init_key is the array for initializing keys */
            /* key_length is its length */
            void init_by_array64(ulong[] init_key, ulong key_length)
            {
                ulong i, j, k;

                init_genrand64(19650218UL);
                i = 1;
                j = 0;
                k = NN > key_length ? NN : key_length;
                for (; k != 0; k--)
                {
                    mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 62)) * 3935559000370003845UL))
                            + init_key[j] + j; /* non linear */
                    i++;
                    j++;
                    if (i >= NN)
                    {
                        mt[0] = mt[NN - 1];
                        i     = 1;
                    }

                    if (j >= key_length)
                    {
                        j = 0;
                    }
                }

                for (k = NN - 1; k != 0; k--)
                {
                    mt[i] = (mt[i] ^ ((mt[i - 1] ^ (mt[i - 1] >> 62)) * 2862933555777941757UL))
                            - i; /* non linear */
                    i++;
                    if (i >= NN)
                    {
                        mt[0] = mt[NN - 1];
                        i     = 1;
                    }
                }

                mt[0] = 1UL << 63; /* MSB is 1; assuring non-zero initial array */
            }

            /* generates a random number on [0, 2^64-1]-interval */
            ulong genrand64_int64()
            {
                int   i;
                ulong x;

                ulong[] mag01 = { 0UL, MATRIX_A };

                if (mti >= NN)
                {
                    /* generate NN words at one time */

                    /* if init_genrand64() has not been called, */
                    /* a default initial seed is used     */
                    if (mti == NN + 1)
                    {
                        init_genrand64(5489UL);
                    }

                    for (i = 0; i < NN - MM; i++)
                    {
                        x     = (mt[i] & UM) | (mt[i + 1] & LM);
                        mt[i] = mt[i + MM] ^ (x >> 1) ^ mag01[(int)(x & 1UL)];
                    }

                    for (; i < NN - 1; i++)
                    {
                        x     = (mt[i] & UM) | (mt[i + 1] & LM);
                        mt[i] = mt[i + (MM - NN)] ^ (x >> 1) ^ mag01[(int)(x & 1UL)];
                    }

                    x          = (mt[NN - 1] & UM) | (mt[0] & LM);
                    mt[NN - 1] = mt[MM - 1] ^ (x >> 1) ^ mag01[(int)(x & 1UL)];

                    mti = 0;
                }

                x = mt[mti++];

                x ^= (x >> 29) & 0x5555555555555555UL;
                x ^= (x << 17) & 0x71D67FFFEDA60000UL;
                x ^= (x << 37) & 0xFFF7EEE000000000UL;
                x ^= x >> 43;

                return(x);
            }

            switch (method)
            {
            case SeedMethod.InitGenRand:
                init_genrand64(seed);
                break;

            case SeedMethod.InitByArray:
                init_by_array64(seeds, (ulong)seeds.Length);
                break;
            }

            var result = new ulong[outputSize];

            for (var i = 0; i < result.Length; ++i)
            {
                result[i] = genrand64_int64();
            }

            return(result);
        }
예제 #5
0
 public PoolGroupBuilder UsingSeed(SeedMethod seedMethod)
 {
     _seedMethod = seedMethod;
     return(this);
 }
        /// <summary>
        /// Migrate and seed the DbContext using the seed delegate.
        /// </summary>
        /// <typeparam name="TContext">The DbContext type</typeparam>
        /// <param name="hostTask">The task that can be awaited to get the host.</param>
        /// <param name="seeder">The seed delegate.</param>
        /// <returns>A task that represents the asynchronous migration operation.</returns>
        public static async Task <IHost> MigrateDbContext <TContext>(this Task <ElseExecuteHost> hostTask, SeedMethod <TContext> seeder)
            where TContext : DbContext
        {
            var host = await hostTask;

            return(await host.MigrateDbContext(seeder));
        }
예제 #7
0
        /// <summary>
        /// Migrate and seed the DbContext using the seed delegate.
        /// </summary>
        /// <typeparam name="TContext">The DbContext type</typeparam>
        /// <typeparam name="TMigrationsConfiguration">The type of the migrations configuration to use during initialization.</typeparam>
        /// <param name="hostTask">The task that can be awaited to get the host.</param>
        /// <param name="seeder">The seed delegate.</param>
        /// <returns>A task that represents the asynchronous migration operation.</returns>
        public static async Task <IHost> MigrateDbContext <TContext, TMigrationsConfiguration>(this Task <ElseExecuteHost> hostTask, SeedMethod <TContext> seeder)
            where TContext : DbContext
            where TMigrationsConfiguration : DbMigrationsConfiguration <TContext>, new()
        {
            var host = await hostTask;

            return(await host.MigrateDbContext <TContext, TMigrationsConfiguration>(seeder));
        }