I'd be a bit worried that you put 14 numbers in that array and then sorted 13 of them.
At least someone notices ![]()
It shows a degree of freedom the algorithm has, you can randomize only first part of the array ![]()
Drawback of algorithms that need to check if there a number is already chosen like the one I proposed myself (last line of prev post) that they can take a large amount of time, especially when the list of numbers to choose from and the numbers needed are in the same order of magnitude.
There is also the algorithm (Dijkstra/Knuth?) that is linear with the amount of numbers. This algorithm generates one number per iteration but it needs an array with all numbers to be chosen from. It works as follows:
take an array of 20 elements.
take one element x=random(20)
remove element x from the array by moving the last element of the array to x
make the array 1 element smaller; //ignore last element
take one element x=random(19)
remove element x from the array by moving the last element of the array to x
make the array 1 element smaller; //ignore last element
etc..
(snippet)
for (int i = 0; i < 5; i++)
{
int x = random(20-i);
Serial.println(array[x]);
array[x] = array[20-i];
}
Drawback of this algorithm is that it needs the array of numbers to choose from.