Use a cryptographically secure pseudorandom number generator

Squashed all of the commits into a single commit.

See also: #128, #130
We require PHP 5.4 for this SDK, so I think this could be simplified.