[BACK]Return to randomize.awk CVS log [TXT][DIR] Up to [Development] / xfs-cmds / xfstests

File: [Development] / xfs-cmds / xfstests / randomize.awk (download)

Revision 1.1, Fri Dec 2 05:03:41 2005 UTC (11 years, 10 months ago) by ajones.longdrop.melbourne.sgi.com
Branch: MAIN
CVS Tags: HEAD

Added randomize test option to ./check
Merge of master-melb:xfs-cmds:24664a by kenmcd.

  A simple awk function that randomizes stdin.

# 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
}

{
    srand()
    for (i = 0; i < NF; i++ ) array[i] = $(i+1)
    randomize(array, NF)
    for (i = 0; i < NF; i++) printf("%s ", array[i])
}