コード例 #1
0
        public override void Generate(Color[] pixels, int width, int height)
        {
            // Get a copy of the base seed
            int localBaseSeed = baseSeed;

            // Array of random number generator instances
            Random[] rnd = new Random[generatorCount];

            // Seed generator for seeding the random number generator instances
            Func <int> seedGen = null;

            // Determine the method of obtaining seeds
            switch (seedOptions)
            {
            case SeedOptions.SameSeeds:
                // Always use the same seed (bad!)
                seedGen = () => localBaseSeed;
                break;

            case SeedOptions.SequentialSeeds:
                // Use incremental seeds
                seedGen = () => localBaseSeed++;
                break;

            case SeedOptions.RandomSeeds:
                // Use random seeds
                Random randSeeder =
                    PRNGHelper.PRNGInstance(randGenerator, localBaseSeed);
                seedGen = () => randSeeder.Next();
                break;
            }

            // Instantiate the random number generators
            for (int i = 0; i < generatorCount; i++)
            {
                rnd[i] = PRNGHelper.PRNGInstance(
                    randGenerator, seedGen.Invoke());
            }

            // Fill vector of pixels with random black or white pixels
            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    // Get a random value to choose a color
                    int colorIndex = rnd[j % rnd.Length].Next(numberOfColors);

                    // Set color in pixels array
                    pixels[i * width + j] = colors[colorIndex];
                }
            }
        }
コード例 #2
0
 public override void Generate(Color[] pixels, int width, int height)
 {
     random = useSeed
         ? PRNGHelper.PRNGInstance(randGenerator, seed)
         : PRNGHelper.PRNGInstance(randGenerator);
 }