22 #include <tensor/rand.h>
35 char *rand_seed = getenv(
"RANDSEED");
37 int seed = atoi(rand_seed);
38 std::cout <<
"RANDSEED=" << seed << std::endl;
42 FILE *fp = fopen(
"/dev/urandom",
"r");
46 rand_uint seed[SEED_SIZE];
47 if (fp && (SEED_SIZE > 0)) {
48 fread(&seed,
sizeof(rand_uint), SEED_SIZE, fp);
50 init_by_array(seed, SEED_SIZE);
56 for (
size_t i = 0; i < 624*10; i++) {
62 static bool mt_initialized = initialize_mt();
65 template<>
int rand<int>() {
return genrand_int63(); }
66 template<>
unsigned int rand<unsigned int>() {
return genrand_int64(); }
67 template<>
long rand<long>() {
return genrand_int63(); }
68 template<>
unsigned long rand<unsigned long>() {
return genrand_int64(); }
70 template<>
int rand<int>() {
return genrand_int31(); }
71 template<>
unsigned int rand<unsigned int>() {
return genrand_int32(); }
72 template<>
long rand<long>() {
return genrand_int31(); }
73 template<>
unsigned long rand<unsigned long>() {
return genrand_int32(); }
76 template<>
float rand<float>() {
77 return genrand_res53();
80 template<>
double rand<double>() {
81 return genrand_res53();
84 template<> cdouble rand<cdouble>() {
85 return to_complex(genrand_res53(), genrand_res53());