Instead of a complete
shuffle, I am looking for a partial
shuffle function in python.
Example : "string" must give rise to "stnrig", but not "nrsgit"
It would be better if I can define a specific "percentage" of characters that have to be rearranged.
Purpose is to test string comparison algorithms. I want to determine the "percentage of shuffle" beyond which an(my) algorithm will mark two (shuffled) strings as completely different.
Here is my code. Improvements are welcome !
import random percent_to_shuffle = int(raw_input("Give the percent value to shuffle : ")) to_shuffle = list(raw_input("Give the string to be shuffled : ")) num_of_chars_to_shuffle = int((len(to_shuffle)*percent_to_shuffle)/100) for i in range(0,num_of_chars_to_shuffle): x=random.randint(0,(len(to_shuffle)-1)) y=random.randint(0,(len(to_shuffle)-1)) z=to_shuffle[x] to_shuffle[x]=to_shuffle[y] to_shuffle[y]=z print ''.join(to_shuffle)