Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save johnmcdowall/529120 to your computer and use it in GitHub Desktop.
Save johnmcdowall/529120 to your computer and use it in GitHub Desktop.
static int GenerateCryptographiclyStrongSeed() {
var randomBytes = new byte[4];
// Generate 4 random bytes.
var rng = new RNGCryptoServiceProvider();
rng.GetBytes(randomBytes);
// Convert 4 bytes into a 32-bit integer value.
return (randomBytes[0] & 0x7f) << 24 |
randomBytes[1] << 16 |
randomBytes[2] << 8 |
randomBytes[3];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment