#!/bin/ksh # brute force method using constant number and table of orders # # make ntr randomizations of 4 items such that no # item occurs twice in a row, and all M items # occur before any item is repeated # this script generates a script that will populate # the folder "dest" with links to the image files # number of trials -- change as needed ntr=100 # list of four image files -- change as needed set -A imgs foo.jpg bar.jpg xxx.jpg yyy.jpg set -A ord4 \ "0 1 2 3" "0 1 3 2" "0 2 1 3" "0 2 3 1" "0 3 1 2" "0 3 2 1" \ "1 0 2 3" "1 0 3 2" "1 2 0 3" "1 2 3 0" "1 3 0 2" "1 3 2 0" \ "2 0 1 3" "2 0 3 1" "2 1 0 3" "2 1 3 0" "2 3 0 1" "2 3 1 0" \ "3 0 1 2" "3 0 2 1" "3 1 0 2" "3 1 2 0" "3 2 0 1" "3 2 1 0" # destination folder -- change as needed dest="randset1" T=/tmp/rand4.$$ trap "rm -f $T" EXIT trap "rm -f $T;exit" INT last=-1 ((tr=0)) while [[ tr -lt ntr ]] ; do eval "set -A this ${ord4[$RANDOM%24]}" if [[ ${this[0]} -eq last ]] ; then continue fi ((ev=0)) while [[ ev -lt 4 ]] ; do img=${imgs[${this[ev]}]} printf "ln -s %s %s/%03d-%d-%s\n" $img $dest $tr $ev $img ((ev++)) done ((tr++)) last=${this[3]} done exit 0