Quote:
Originally Posted by sushi4664
Wait what did u misunderstand? Is it something that I need to clear up?
Yea, I think I will go back to this method, it only makes sense that this would be faster. Though, if anyone has the run time analysis on these pieces of code, that would be really nice. Or even some clarification on how the shuffle method works and how processor consuming it is.
|
It should be much faster because a shuffle is like a sort and sorting takes a lot of time, but the way it's written it won't work as expected. It's missing one line of code to make it work properly.
The way it's written, when a random number is picked it unsets that element.
So in the array that element will be missing.
Say for instance you have 4 elements then the count would be four.
A rand number of 2 comes up and the third element gets unset.
Now you have a count of 3.
So if a rand number of 2 comes up next the third element will not be there because it was unset.
So the remaining elements need to be merged so the indexing is correct.
Then it will work without any problems.
Like this: