Q: How to show every result from awk rand() loop in separated files? I'm trying to generate several files with random column, using awk. And then paste each two into one file with two columns. This will be an input to another program. The problem that I'm facing is that I get only the last iteration in one file.
The code I'm using is:
awk 'BEGIN {
srand();
total=5;
max1=10;
count=0;
    while(count < total) {
    rnd1 = int(rand() * max1);
    if ( array[rnd1] == 0 ) {
        count++;
        array[rnd1]++;
    }
}

for ( i=0; i<=200; i++) {
    if ( array[i] )
        print i;
}
}' > out1

awk 'BEGIN {
srand();
total=5;
max2=20;
count=0;
    while(count < total) {
    rnd2 = int(rand() * max2);
    if ( array[rnd2] == 0 ) {
        count++;
        array[rnd2]++;
    }

}

for ( j=0; j<=max2; j++) {
    if ( array[j] )
        print j;
}
}' > out2

paste out1 out2 | awk '{ print "  "$1".0" , $2".0"; }' > out3

Is there a better way to get all the iterations in separate files ?
The output I'm getting is :
  1.0 2.0
  3.0 7.0
  4.0 9.0
  6.0 12.0
  9.0 13.0

which is fine, but it's in one file "out3", I want to get all the iteration files "out(i)" files.

A: Redirecting to file using > will erase the content of the file. Use >> instead, and follow the docs for further help.

print items >> output-file
This redirection prints the items into the preexisting output file
named output-file. The difference between this and the single-'>'
redirection is that the old contents (if any) of output-file are not
erased. Instead, the awk output is appended to the file. If
output-file does not exist, then it is created.

For example:
for ( i=0; i<=200; i++) {
    if ( array[i] )
        print i;
}
}' > out1

will erase the content of out1 at each iteration. Only the last iteration will be actually saved in out1 without being over-written.
