Random key generator.

fixes #396