The algorithm produces all the numbers in a set count from 1… n, with n being the size of the array. The C# sort methods are explained in the earlier blog here: C# Array Sort with Unity – WebGL.

NoRepeat

 

        int max = numberInSet; //max is the size of the array elements
        int min = 1;

        int count = max - min + 1;
        int[] generatedList = new int[count];//new array

        for (int i = 0; i < count; i++)//Start array creation
        {
            //Generate random number
            int j = UnityEngine.Random.Range(0, i + 1);

            generatedList[i] = generatedList[j];
            generatedList[j] = min + i;
        }

Published by Trine Epiphany

Leave a Reply

Your email address will not be published. Required fields are marked *