It should "sufficiently" shuffle your lines.
However, if you're
pedantic about the degree of "randomness", you have to send it through the alias several times, due to the way it works.
; randomtest <S> <L> <I> <R>
; S = Set (total numbers) (N)
; L = Line to show distribution for (N out of S)
; I = Iteration runs (N)
; R = Randomize repetitions (N)
alias randomtest {
if ($1 isnum 1-) && ($2 isnum 1- $+ $1) && ($3 isnum 1-) && ($4 isnum 1-) {
echo -sg $3 iterations on a set of $1 lines, randomized $4 time(s). Line $qt($2) found at position:
var %s = 1, %l = 1, %i = 1, %result
; create set S
window -h @rand.in
while (%s <= $1) { aline @rand.in $v1 | inc %s }
; I iteration runs
hmake randomize
window -h @rand.out
while (%i <= $3) {
; randomize set R times
var %r = 1
while (%r <= $4) { filter -wwca $iif((%r == 1),@rand.in,@rand.out) @rand.out randomsort | inc %r }
; count positions of L
hinc randomize $fline(@rand.out,$2,1)
inc %i
}
; distribution result
while (%l <= $1) { %result = $iif(%result,$v1 ---) %l : $hget(randomize,%l) $+ x | inc %l }
echo -sg %result
window -c @rand.in | window -c @rand.out
hfree randomize
}
}
A single run shows noticeable "clusters":
/randomtest 5 1 5000 1
5000 iterations on a set of 5 lines, randomized 1 time(s). Line "1" found at position:
1 : 1434x --- 2 : 1347x --- 3 : 1079x --- 4 : 787x --- 5 : 353x
/randomtest 5 3 5000 1
5000 iterations on a set of 5 lines, randomized 1 time(s). Line "3" found at position:
1 : 1128x --- 2 : 873x --- 3 : 1209x --- 4 : 958x --- 5 : 832x
/randomtest 5 5 5000 1
5000 iterations on a set of 5 lines, randomized 1 time(s). Line "5" found at position:
1 : 543x --- 2 : 729x --- 3 : 739x --- 4 : 1021x --- 5 : 1968x
With three runs, they're almost gone:
/randomtest 5 1 5000 3
5000 iterations on a set of 5 lines, randomized 3 time(s). Line "1" found at position:
1 : 1010x --- 2 : 1021x --- 3 : 1067x --- 4 : 935x --- 5 : 967x
/randomtest 5 3 5000 3
5000 iterations on a set of 5 lines, randomized 3 time(s). Line "3" found at position:
1 : 984x --- 2 : 952x --- 3 : 1026x --- 4 : 1046x --- 5 : 992x
/randomtest 5 5 5000 3
5000 iterations on a set of 5 lines, randomized 3 time(s). Line "5" found at position:
1 : 919x --- 2 : 984x --- 3 : 992x --- 4 : 996x --- 5 : 1109x
Just for your information
