Added code for random key generation