Files
apfstests/randomize.awk
T
Darrick J. Wong 07094a9652 check: improve test list randomization
awk doesn't have a particularly good random number generator -- it seeds
from the Unix epoch time in seconds, which means that the run order
across a bunch of VMs started at exactly the same time are unsettlingly
predictable.  Therefore, at least try to seed it with bash's $RANDOM,
which is slightly less predictable.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
2019-03-23 21:27:12 +08:00

29 lines
438 B
Awk

# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2005 Silicon Graphics, Inc. All Rights Reserved.
#
# randomize stdin.
function randomize(array, N) {
for(i = 0; i < N; i++) {
j = int(rand()*N)
if ( i != j) {
tmp = array[i]
array[i] = array[j]
array[j] = tmp
}
}
return
}
BEGIN {
srand(seed)
}
{
array[NR - 1] = $0
}
END {
randomize(array, NR)
for (i = 0; i < NR; i++) printf("%s ", array[i])
}