Jun-03-2019, 09:49 PM
(This post was last modified: Jun-03-2019, 09:49 PM by michalmonday.)
random.randint
requires 2 input arguments so that's what error indicates. Input arguments supposed to be 2 integers. But there's another issue, it returns single value. You could either use list comprehension to produce a list or use the numpy.random.randint
instead which returns the whole array.# settings low_border = 1 # inclusive high_border = 100 # inclusive list_size = 30 # 1st way import random a = [random.randint(low_border, high_border) for _ in range(list_size)] b = [random.randint(low_border, high_border) for _ in range(list_size)] c = [i for i in b if i in a] print('1ST WAY:', a, b, c, sep='\n\n') print('\n\n\n') # 2nd way import numpy as np np_a = np.random.randint(low_border, high_border + 1, list_size) np_b = np.random.randint(low_border, high_border + 1, list_size) np_c = np.intersect1d(np_a, np_b) # it sorts the values (idk if that's desired) print('2ND WAY:', np_a, np_b, np_c, sep = '\n\n')
Output:1ST WAY:
[75, 53, 99, 84, 40, 76, 79, 64, 94, 95, 56, 73, 20, 94, 24, 56, 100, 66, 2, 92, 71, 84, 44, 58, 8, 12, 7, 45, 49, 62]
[64, 80, 91, 69, 16, 73, 4, 26, 46, 6, 64, 24, 61, 38, 39, 85, 94, 56, 38, 50, 44, 96, 100, 16, 52, 30, 47, 3, 15, 87]
[64, 73, 64, 24, 94, 56, 44, 100]
2ND WAY:
[80 73 45 52 46 65 74 72 28 74 54 80 92 23 27 60 66 51 73 42 47 15 71 68
91 4 25 36 44 44]
[ 91 67 74 99 58 86 89 49 45 92 78 6 22 26 51 90 88 31
9 75 75 73 42 15 100 86 41 86 29 66]
[15 42 45 51 66 73 74 91 92]