Guest User

Untitled

a guest
Jun 20th, 2019
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import sys
  2. import argparse
  3. from random import randint
  4.  
  5.  
  6. parser = argparse.ArgumentParser(description="Hello, please give the array of population iteams and the \
  7. number of items to be chosen")
  8. parser.add_argument('-l', '--list', help='Comma separated delimited list input', type=str)
  9. parser.add_argument('number', help='The number of items to be chosen')
  10. args = parser.parse_args()
  11.  
  12.  
  13. population = [int(item) for item in args.list.split(',')]
  14. print(population)
  15. m = args.number
  16.  
  17.  
  18. def SelectionSampling(population, m):
  19. m = int(m) #Is there a better way to right this?
  20. S = []
  21. k, t = 0, 0
  22. n = len(population)
  23. while k < m:
  24. u = randint(0, 1)
  25. if u * (n - t) < (m - k):
  26. S.append(population[t]) # List index out of range
  27. k += 1
  28. t += 1
  29. return S
  30.  
  31.  
  32. sample = SelectionSampling(population, m)
  33. print(sample)
Advertisement
Add Comment
Please, Sign In to add comment