daily pastebin goal
55%
SHARE
TWEET

Untitled

a guest Jan 16th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2.  
  3. # stream shuffling can be done if the output stream has random read/write
  4. # we use the fisher yates shuffling algorithm
  5.  
  6. input_list = [1,2,3,4,5]
  7.  
  8. output_list = []
  9.  
  10. for (i, v) in enumerate(input_list):
  11.     output_list.append(v)
  12.     j = random.randint(0, i)
  13.     if j != i:
  14.         output_list[i] = output_list[j]
  15.         output_list[j] = v
  16.  
  17. # if the output stream was a fixed size stream
  18.  
  19. output_list = [None] * len(input_list)
  20.  
  21. for (i, v) in enumerate(input_list):
  22.     j = random.randint(0, i)
  23.     if j != i:
  24.         output_list[i] = output_list[j]
  25.     output_list[j] = v
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top