I want to add a shuffle option in my android music player app. For that purpose i am calling a random function in java to return a number between 0 and size of the currently playing songs list. The problem is that the function returns same value as before and repetitions happens in the value. There are many solutions available in stack overflow herself to avoid this problem. That solutions as well as the following will not work in my case. 1. Creating a shuffled array contains 0 to maximum list size value. It will fail because the size of the songs list is dynamic. 2. Shuffling the songs list array itself. it will fail because of the time complexity.
What i need is a mathematical hash function which will do the following..
If 50 is the maximum range, then the input number 1 will map to any other number say 34. Input 2 to any other number say 21. Input 3 to any other number say 10 Etc. All the mapped numbers should be within the range 50 and no repetitions are allowed. (No coalition while mapping ) also mapping to that number is not allowed. Please note that if the maximum range is same (in this case 50)and the input number 2 to this function should return the value 21 at anytime throughout the application.
The function time complexity should be less.