So I have a piece of code:
def test(num):
count = 1
l = []
while len(l) < 16:
x = num % count
if x >= 16 or x in l:
pass
else:
l.append(x)
count += 1
return l
that takes a number 45071
for example and modulos it with count
, which starts at 1 and goes up by one every loop cycle. Then, if 45071 % count
is less than 16, it is appended to a list unless the same value is already there. This loop stops once there are 16 numbers in the list, from 0 to 15. Here is the results of a test run:
>>> print(test(45071))
[0, 1, 2, 3, 5, 7, 8, 4, 11, 15, 14, 13, 12, 6, 9, 10]
This works and all, but with bigger lists and lots of different numbers it gets quite slow. I was wondering if there is any way to make this faster, or another way to get a list of numbers from 0 to 15. The more 'random' the numbers the better. Thanks in advance!