Fixes for example: https://travis-ci.org/bitcoin/bitcoin/jobs/46093269 and https://travis-ci.org/bitcoin/bitcoin/jobs/46114383
on rare occasions, rand() was returning duped values, causing duplicate transactions.
BuildMerkleTree happily used these, but CPartialMerkleTree caught them and returned a null merkle root.
Rather than taking chances with rand(), use the loop counter to guarantee unique values.
At sipa's request, also remove the remaining uses of rand().