Upgrade GenerateNonce function.