mardi 6 juin 2017

Creating Clumped Distribution of Random Numbers On a 2d Int Array

I am creating a program that generates a random assortment of colors depending on which colors are selected. Color Assortment Program

I am trying to come up with a way to "clump" the colors together, and I can't decide whether this should be done after (re-organizing) or during the random generation. By this I mean that if there was just a green block on the previous step of either direction on the 2d array, then there is a higher chance of another green block being rendered than any other block.

I'm just really stuck on how exactly I could get this to work.

My current generating Code:

            public static int[,] Randomgeneration(Block_Map_Array.Form1 f)
    {
        Random rnd = new Random();
        int[,] generated = new int[100,100];
        List<int> numbers = new List<int>();
        numbers = GetColors(f); // Gets selected colors for randomizing
        for (int i = 0; i < generated.GetLength(0); i++)
        {
            for (int j = 0; j < generated.GetLength(1); j++)
            {
                generated[i, j] = numbers[rnd.Next(0, numbers.Count)];
            }
        }

In the numbers list, 1 is blue, 2 is red, 3 is green, 4 is orange, and 5 is purple. (The list may contain 2, 3, 5 or any other order selected by the user). This is converted in my WinForm code section (where the method is called).

Does anyone know how I could get this sort've 2 way weighted distribution to work?




Aucun commentaire:

Enregistrer un commentaire