Replace rand function with more secure SecureRandom.hex

Standard rand function can be predictable under some edge cases or if running the function multiple times.