Created
October 24, 2016 10:44
-
-
Save slhck/a88d3ff46d782bb77db21618fc438fdf to your computer and use it in GitHub Desktop.
Shuffle playlists for SRC-HRC randomization without repeating SRCs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
from pprint import pprint | |
sources = 2 | |
conditions = 2 | |
subjects = 3 | |
playlists = {} | |
for subject in range(1, subjects + 1): | |
playlist = [] | |
it = 1 | |
all_pvs_conditions = list(xrange(1, conditions + 1)) * sources | |
while True: | |
# end if no more are available | |
if len(playlist) == sources * conditions: | |
break | |
src_list_shuffled = list(xrange(1, sources + 1)) | |
while len(src_list_shuffled): | |
next_src = random.choice(src_list_shuffled) | |
next_condition = random.choice(all_pvs_conditions) | |
if [next_src, next_condition] not in playlist: | |
src_list_shuffled.remove(next_src) | |
all_pvs_conditions.remove(next_condition) | |
playlist.append([next_src, next_condition]) | |
playlists[subject] = playlist | |
pprint(playlists) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment