Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randrange
- l = 10
- t = 50000
- def shuffle_from_pos(arr):
- for i in xrange(l):
- j = randrange(i, l)
- arr[i], arr[j] = arr[j], arr[i]
- return arr
- # copy pased from:
- # http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#Sattolo.27s_algorithm
- def sattoloCycle(items):
- i = len(items)
- while i > 1:
- i = i - 1
- j = randrange(i) # 0 <= j <= i-1
- items[j], items[i] = items[i], items[j]
- return items
- def test(f):
- rv = [0]*l
- for i in xrange(t):
- rv = map(sum, zip(rv, f(range(l))))
- return rv
- def normalize(arr):
- s = float(sum(arr))
- return map(lambda a: "%.4f" % (a/s), arr)
- print "each element can be moved to places after it or stay still"
- print normalize(test(shuffle_from_pos))
- print "Sattolo's algorithm, copy pasted from wiki"
- print normalize(test(sattoloCycle))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement