Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

Don't use using in your headers

#Don't use using in your headers EveryoneEveryone who uses the header will have string, vector, mt19937_64, uniform_int_distribution and istream in the global namespace whether they want them or not. It's not what I expect when I write #include "PasswordGenerator.h", and it's poor practice to inflict that on your (削除) victims (削除ここまで) users.

Avoid floating-point arithmetic.

#Avoid floating-point arithmetic. There'sThere's nothing here that can't be done with integers. Using integer types avoids all sorts of precision and rounding issues you'd prefer not to think about. The same goes for (int)pow(2, n) where a simple 1<<n would do.

Don't reduce a uniform range by modulo operator.

This is a biased sampling:

uniform_int_distribution<int> dist(0, maxRange);
auto rnd = bind(dist, mt64);
// ...
int start = rnd() % stringsSize;

Instead, create a distribution of the required range:

std::uniform_int_distribution<int> strings_dist(0, stringsSize);
int start = strings_dist(mt64);

Remember, you can use several distributions with the single generator - that's one of the reasons they are designed to be separable.

#Don't use using in your headers Everyone who uses the header will have string, vector, mt19937_64, uniform_int_distribution and istream in the global namespace whether they want them or not. It's not what I expect when I write #include "PasswordGenerator.h", and it's poor practice to inflict that on your (削除) victims (削除ここまで) users.

#Avoid floating-point arithmetic. There's nothing here that can't be done with integers. Using integer types avoids all sorts of precision and rounding issues you'd prefer not to think about. The same goes for (int)pow(2, n) where a simple 1<<n would do.

Don't reduce a uniform range by modulo operator.

This is a biased sampling:

uniform_int_distribution<int> dist(0, maxRange);
auto rnd = bind(dist, mt64);
// ...
int start = rnd() % stringsSize;

Instead, create a distribution of the required range:

std::uniform_int_distribution<int> strings_dist(0, stringsSize);
int start = strings_dist(mt64);

Remember, you can use several distributions with the single generator - that's one of the reasons they are designed to be separable.

Don't use using in your headers

Everyone who uses the header will have string, vector, mt19937_64, uniform_int_distribution and istream in the global namespace whether they want them or not. It's not what I expect when I write #include "PasswordGenerator.h", and it's poor practice to inflict that on your (削除) victims (削除ここまで) users.

Avoid floating-point arithmetic.

There's nothing here that can't be done with integers. Using integer types avoids all sorts of precision and rounding issues you'd prefer not to think about. The same goes for (int)pow(2, n) where a simple 1<<n would do.

Don't reduce a uniform range by modulo operator.

This is a biased sampling:

uniform_int_distribution<int> dist(0, maxRange);
auto rnd = bind(dist, mt64);
// ...
int start = rnd() % stringsSize;

Instead, create a distribution of the required range:

std::uniform_int_distribution<int> strings_dist(0, stringsSize);
int start = strings_dist(mt64);

Remember, you can use several distributions with the single generator - that's one of the reasons they are designed to be separable.

Use the uniform distribution properly.
Source Link
Toby Speight
  • 87.3k
  • 14
  • 104
  • 322

#Don't use using in your headers Everyone who uses the header will have string, vector, mt19937_64, uniform_int_distribution and istream in the global namespace whether they want them or not. It's not what I expect when I write #include "PasswordGenerator.h", and it's poor practice to inflict that on your (削除) victims (削除ここまで) users.

#Avoid floating-point arithmetic. There's nothing here that can't be done with integers. Using integer types avoids all sorts of precision and rounding issues you'd prefer not to think about. The same goes for (int)pow(2, n) where a simple 1<<n would do.

Don't reduce a uniform range by modulo operator.

This is a biased sampling:

uniform_int_distribution<int> dist(0, maxRange);
auto rnd = bind(dist, mt64);
// ...
int start = rnd() % stringsSize;

Instead, create a distribution of the required range:

std::uniform_int_distribution<int> strings_dist(0, stringsSize);
int start = strings_dist(mt64);

Remember, you can use several distributions with the single generator - that's one of the reasons they are designed to be separable.

#Don't use using in your headers Everyone who uses the header will have string, vector, mt19937_64, uniform_int_distribution and istream in the global namespace whether they want them or not. It's not what I expect when I write #include "PasswordGenerator.h", and it's poor practice to inflict that on your (削除) victims (削除ここまで) users.

#Avoid floating-point arithmetic. There's nothing here that can't be done with integers. Using integer types avoids all sorts of precision and rounding issues you'd prefer not to think about.

#Don't use using in your headers Everyone who uses the header will have string, vector, mt19937_64, uniform_int_distribution and istream in the global namespace whether they want them or not. It's not what I expect when I write #include "PasswordGenerator.h", and it's poor practice to inflict that on your (削除) victims (削除ここまで) users.

#Avoid floating-point arithmetic. There's nothing here that can't be done with integers. Using integer types avoids all sorts of precision and rounding issues you'd prefer not to think about. The same goes for (int)pow(2, n) where a simple 1<<n would do.

Don't reduce a uniform range by modulo operator.

This is a biased sampling:

uniform_int_distribution<int> dist(0, maxRange);
auto rnd = bind(dist, mt64);
// ...
int start = rnd() % stringsSize;

Instead, create a distribution of the required range:

std::uniform_int_distribution<int> strings_dist(0, stringsSize);
int start = strings_dist(mt64);

Remember, you can use several distributions with the single generator - that's one of the reasons they are designed to be separable.

Source Link
Toby Speight
  • 87.3k
  • 14
  • 104
  • 322

#Don't use using in your headers Everyone who uses the header will have string, vector, mt19937_64, uniform_int_distribution and istream in the global namespace whether they want them or not. It's not what I expect when I write #include "PasswordGenerator.h", and it's poor practice to inflict that on your (削除) victims (削除ここまで) users.

#Avoid floating-point arithmetic. There's nothing here that can't be done with integers. Using integer types avoids all sorts of precision and rounding issues you'd prefer not to think about.

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /