The biggest problem with your scripting seems to be that you don't really know what tools are available and what options they have. My recommendation would be for you to just see what comes included with the coreutils and busybox, you'll find all kinds of wonderful little tools there.

In bash my solution to this would be this single line:

    paste ./ranks.txt ./position.txt &lt;(shuf -n 10  first.txt) &lt;(shuf -n 10 last.txt)

If you don't mind two crewmen having two the same name then you can add -r to the shuf flags, at least when using GNU coreutils.

Since busybox' ash lacks the wonderful process substitution of bash (the &lt;(cmd) in the above) I would probably just do something like this:

    while read -r x do
      printf '%s %s %sn' "$x" "$(shuf -n 1 first.txt)" "$(shuf -n 1 last.txt)"
    done &lt;(paste ranks.txt position.txt)

With larger files this ash compatible version would be quite inefficient and slow but I doubt that really matters here.