Используя random.choice
Я сделал это проще - и теперь он работает правильно.
import random
digits = ['0', '1','2','3']
word = ['word1', 'word2']
images = ['image1', 'image2', 'image3']
trials = []
d = random.choice(digits)
w = random.choice(word)
i = random.choice(images)
trials.append( (d,w,i) )
while (d,w,i) in trials:
d = random.choice(digits)
w = random.choice(word)
i = random.choice(images)
trials.append( (d,w,i) )
print(trials)
РЕДАКТИРОВАТЬ: это работает с индексами
import random
trials = []
trial_index = 0
digits = ['0', '1', '2', '3']
word = [ "word1", "word2"]
images = ['image1', 'image2', 'image3']
digit_index = random.randint(0, 3)
word_index = random.randint(0, 1)
image_index = random.randint(0, 2)
selected_trial = (digit_index, word_index, image_index)
trials.append( selected_trial )
trial_index += 1
#trial_index = len(trials)
while selected_trial in trials:
digit_index = random.randint(0, 3)
word_index = random.randint(0, 1)
image_index = random.randint(0, 2)
selected_trial = (digit_index, word_index, image_index)
trials.append( selected_trial )
trial_index += 1
#trial_index = len(trials)
print( trials )