23 #include <tensor/numbers.h>
39 template<
class number> number rand() {
40 return static_cast<number
>(rand<double>());
43 template<>
int rand<int>();
44 template<>
unsigned int rand<unsigned int>();
45 template<>
long rand<long>();
46 template<>
unsigned long rand<unsigned long>();
47 template<>
float rand<float>();
48 template<>
double rand<double>();
49 template<> cdouble rand<cdouble>();
51 template<
class real_number>
inline real_number rand(real_number upper_limit) {
52 return static_cast<real_number
>(upper_limit * rand<double>());
55 template<
class real_number>
inline real_number rand(real_number lower_limit,
56 real_number upper_limit) {
57 return rand<real_number>(upper_limit - lower_limit) + lower_limit;
60 template<>
inline int rand<int>(
int upper) {
62 return rand<unsigned int>() % upper;
66 template<>
inline int rand<int>(
int lower,
int upper) {
67 return rand<int>(upper - lower) + lower;
70 template<>
inline long rand<long>(
long upper) {
72 return (
long)rand<unsigned long>() % upper;
76 template<>
inline long rand<long>(
long lower,
long upper) {
77 return rand<long>(upper - lower) + lower;
80 template<>
inline unsigned long rand<unsigned long>(
unsigned long upper) {
82 return rand<unsigned long>() % upper;
86 template<>
inline unsigned long rand<unsigned long>(
unsigned long lower,
unsigned long upper) {
87 return rand<unsigned long>(upper - lower) + lower;
91 #endif // !TENSOR_RAND_H