Skip to content

Commit

Permalink
lfortran_intrinsics.c: Fix random_number()
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaikh-Ubaid committed Jan 21, 2024
1 parent cac71d1 commit 02a3b61
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/libasr/runtime/lfortran_intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1884,13 +1884,22 @@ LFORTRAN_API double _lfortran_time()
#endif
}

bool lfortran_rand_seed = true;
LFORTRAN_API void _lfortran_sp_rand_num(float *x) {
srand(time(0));
if (lfortran_rand_seed) {
srand((unsigned int)clock());
rand();
lfortran_rand_seed = false;
}
*x = rand() / (float) RAND_MAX;
}

LFORTRAN_API void _lfortran_dp_rand_num(double *x) {
srand(time(0));
if (lfortran_rand_seed) {
srand((unsigned int)clock());
rand();
lfortran_rand_seed = false;
}
*x = rand() / (double) RAND_MAX;
}

Expand Down

0 comments on commit 02a3b61

Please sign in to comment.