How about using a generator and while loop?
from random import randrange
def rand(val, repeat=4):
j = 1
while j <= repeat:
yield randrange(val)
j += 1
final = list(rand(10))
Output:
[2, 6, 8, 8]
Also using recursion:
from random import randrange
def rand(val, repeat=4, b=1, temp=[]):
if b < repeat:
temp.append(randrange(val))
return rand(val, b= b+1, temp=temp)
else:
return temp + [randrange(val)]
final = rand(10)
print(final)
Output:
[1, 9, 3, 1]