Use mktemp instead of $RANDOM to generate unique names

Using $RANDOM is not safe because collisions can occur. An example of
such a failure is available here:
https://s3.amazonaws.com/archive.travis-ci.org/jobs/23572639/log.txt

Using mktemp avoids this issue and removes the dependency on bash.
Merge pull request #1005 from ranma42/race-free-parallel-build

Use mktemp instead of $RANDOM to generate unique names