Breaking a file into three new files, character by character

$ cat r.awk 
BEGIN {FS=""; srand()}
{ for (i=1; i<=NF; i++) {
    r=int(n*rand())+1
    for (f=1; f<=n; f++)
      s[f]=s[f] (f==r ? $i : " ")
  }
  for (f=1; f<=n; f++)
    print s[f] >> ("file"f)
  delete s
}

$ cat data
1234567890
1234567890
1234567890
1234567890
1234567890

$ awk -f r.awk n=3 data 

$ cat file1
  3       
12     8  
 2 4 6    
12 4  78  
1234 6 89 

$ cat file2
12 45 78  
  3     90
  3    8  
    56  9 
    5 7  0

$ cat file3 
     6  90
   4567   
1   5 7 90
  3      0

I changed the code of this post after vidyadhar85 nominated it. Apologies if that's frowned upon, but i thought a parameterized version would be even better.

The original code was:

function chk_char(f,c) { if (f!=r) c=" "; return c} 
BEGIN {FS=""; srand()}
{ for (i=1; i<=NF; i++) {
    r=int(3*rand())+1
    s1=s1 chk_char(1,$i)
    s2=s2 chk_char(2,$i)
    s3=s3 chk_char(3,$i)
  }
  print s1 >> "file1"
  print s2 >> "file2"
  print s3 >> "file3"
  s1=s2=s3=""
}