This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 18th, 2012  |  syntax: Python  |  size: 0.33 KB  |  views: 39  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import random
  2.  
  3. def randomperm(n):
  4.     x = range(n)
  5.     for i in xrange(n):
  6.         r = random.randint(i,n-1)
  7.         (x[i],x[r]) = (x[r], x[i])
  8.     return x
  9.  
  10. if __name__ == "__main__":
  11.     import sys
  12.     if len(sys.argv) < 2:
  13.         print "usage: python randomperm n"
  14.     n = int(sys.argv[1])
  15.     print randomperm(n)
clone this paste RAW Paste Data