Consider the template member function that generates a random number
within a range.
#include <cstdlib>
#include <ctime>
#include <iostream>
template<typename T>
T Random(T bottom, T top)
{
return T( (double(rand()) * (top - bottom + 1)) /
(double(RAND_MAX) + 1) ) + bottom;
}
From what I understand the code was found here, nonetheless it's been
the subject of discussion between two team members (call them A and B)
for two reasons:
1.
Team member 'A' claims that a random number generator in most of (if
not say 'all of') the cases returns integer or double values only,
(sometimes with chars but rarely) hence using template here is not
necessary?
2.
He also claims that his judgement might be wrong might be wrong by
proof of generating random objects of unknown types but casting (----)
to double then casting again to T would appear meaningless in the
'sense' of templatized parameters...?
Personally (Team member C :)) I dont see any issues with the code but
I'm not smart enough on random numbers to answer his claims.
Thanks for input.