Use a cryptographically secure pseudorandom number generator

Squashed all of the commits into a single commit.

See also: #128, #130