KunyiLockeLin/AnemoneerEngine

QeMath::Random

Closed this issue · 1 comments

You have different code definitions for separate data types, such as iRandom and fRandom, but the methods themselves are mostly similar. I suggest you merge the methods and in place turn it into a template function.

For example, doing this:

template <typename T>
T random(T min, T max)
{
	if (!max) return min; //This will never run by the way; the method cannot be called when the parameter does not default to anything.
	std::random_device rd;
	std::default_random_engine gen = std::default_random_engine(rd());
	std::uniform_int_distribution<int> dis(min, max); //There's no reason for min + range, this will only potentially add extra, unneeded instructions when the program is compiled.

	return dis(gen);
}

@Drahsid Thank you so much for your suggestion. Now, I am refactoring the code. I will modify it in next update.