我正在創建一個具有三個條件(0,1,2)的條件實驗,並且需要對條件順序進行僞隨機化。我需要一個隨機列表,每個條件連續出現兩次。在這裏,我試圖實現它。該代碼正在運行,但它需要一個永恆...僞隨機化一個列表而不重複; while循環效率不高
任何想法,爲什麼此代碼不能很好地工作,以及任何不同的方法來解決問題?
#create a list with 36 values
types = [0] * 4 + [1] * 18 + [2]*14 #0=CS+ ohne Verstärkung; 1 = CS-, 2=CS+ mit shock
#random.shuffle(types)
while '1,1,1' or '2,2,2' or '0,0,0' in types:
random.shuffle(types)
else: print(types)
預先感謝您! 馬丁娜
連續兩次或最多連續兩次? – tdelaney
另一個類似的問題:http://stackoverflow.com/questions/3313590/check-for-presence-of-a-sliced-list-in-python –