09-27-2010 07:27 AM
I am trying to modify a given list (1-1000) to new one which have the same numbers but without having numbers twice. The new list should mixed from a random function. For example (1, 2, 3 … 5) -> (2, 4, 1, 3, 5)
Any help/ideas are welcome and appreciated.
WTD
Solved! Go to Solution.
09-27-2010 09:52 AM
If all you want is a shuffle type of operation on a list, then it is fairly straight-forward:
void Shuffle (int num_in_list, int *list) { // Deck-of-cards type shuffle
int item, swap, loop;
for (loop = num_in_list; loop > 1; loop--) { // Move down the list
swap = loop * rand () / (RAND_MAX + 1); // Choose a random item from the original list
item = list [swap]; // Remember it
list [swap] = list [loop - 1]; // Exchange it with the top one of the new list
list [loop - 1] = item;
}
}
But I'm not sure what you mean by your requirement of "without having numbers twice". The above function will not repeat a list entry, if that's all you want.
JR
09-28-2010 01:05 AM
Thanks you very much! The function works very well.
08-13-2021 11:09 AM
Thank you for this. I was able to use the information to create a very efficient and useful VI in LabVIEW 2013.