Code:
Problem description:
I'm sure I could figure this out one, if I had the time, but I don't have much of that these days. What would the best way to reorder a list randomly while keeping all the items be?
Thank you for the advice Ter, I never even stopped to think of storing a list length as a local var. I'm sure this will be very helpful in speeding up my procs, because I had used length(list) alot of times in loops already.
The only thing I don't fully understand is if by random chance the pos2 is the same as the pos, and that item does not get swapped, will it be checked again until it is swapped? Would I have to use a while loop, and a counter to make sure every item is moved, or would that not be feasable? |
This swapping method may shuffle multiple indices multiple times, but it will ensure that each item is moved at least once.
Also note that if list is passed as an instance member, you should store it as a local variable for the duration of the sort. This removes unneeded lookups. If it's passed as an argument, it's fine too, as arguments are just special local variables.