1
0
mirror of https://github.com/bitcoinbook/bitcoinbook synced 2024-11-22 08:08:11 +00:00

Stop using numeric_limits for the constant "255", and fix a bug.

The bug is that `x % 255` is not quite the same thing as `x % 256`;
but `x & 255` is.

The stylistic issue is that `numeric_limits<uint8_t>::max()` is a
very verbose way of spelling `255`.
This commit is contained in:
Arthur O'Dwyer 2018-03-25 20:17:35 -07:00
parent f8b883dcd4
commit 9504d804e0

View File

@ -45,7 +45,7 @@ bc::ec_secret random_secret(std::default_random_engine& engine)
bc::ec_secret secret;
// Iterate through every byte setting a random value...
for (uint8_t& byte: secret)
byte = engine() % std::numeric_limits<uint8_t>::max();
byte = engine() & 255;
// Return result.
return secret;
}