Language: Python
# Deutsche bank's online banking page uses a O(n^3) algorithm to generate a
# random character array.
# This is a O(n) way to do the same, for any array.
def randomPermute(array):
import random
for i in range(len(array)):
randIndex=random.randint(i,len(array)-1)
(array[i],array[randIndex])=(array[randIndex],array[i])
return array
# Lets experiment with the english alphabet
import string
print randomPermute(list(string.ascii_letters[:26]))
No comments:
Post a Comment