Solution depends on whether random number can be repeated or no.
random_values = [ random.randint(0, 500) for i in range(100) ]
odd = [ x for x in random_values if x % 2 ]
even = [ x for x in random_values if not x % 2 ]
And If You would like to get unique random number I would propose You to use shuffle
random_values = random.sample(range(0, 500), 100)
odd = [ x for x in random_values if x % 2 ]
even = [ x for x in random_values if not x % 2 ]
You can reduce memory usage using generators for example
random_values = (random.randint(0, 500) for i in xrange(100))
odd = []
even = []
for val in random_values:
if val % 2:
odd.append(val)
else:
even.append(val)
randomval()function doesn't return what you expected to get?return size. then callrandomval()function 100 times. then you are done.returnis now in the way and you seem to have forgotten to include a loop, but it's more of an attempt at coding it yourself now.