Advertisement
jack06215

[tutorial] randomly generate 0 and 1 vector

Sep 26th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.25 KB | None | 0 0
  1. import random
  2.  
  3. # list size
  4. list_size = 10
  5.  
  6. # define num of 0 and 1
  7. zero_count = random.randint(0, 5)
  8. one_count = list_size - zero_count
  9.  
  10. # randomly create 0 and 1
  11. my_list = [0]*zero_count + [1]*one_count
  12. random.shuffle(my_list)
  13. print(my_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement