Skip to content

Commit e6bacfa

Browse files
authored
chore: apply suggestions from code review
Signed-off-by: Philipp Burckhardt <pburckhardt@outlook.com>
1 parent 30fcf84 commit e6bacfa

File tree

1 file changed

+14
-3
lines changed
  • lib/node_modules/@stdlib/stats/base/dists/bernoulli/quantile/benchmark/c

1 file changed

+14
-3
lines changed

lib/node_modules/@stdlib/stats/base/dists/bernoulli/quantile/benchmark/c/benchmark.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ static double tic( void ) {
7474
return (double)now.tv_sec + (double)now.tv_usec/1.0e6;
7575
}
7676

77+
/**
78+
* Generates a random number on the interval [min,max).
79+
*
80+
* @param min minimum value (inclusive)
81+
* @param max maximum value (exclusive)
82+
* @return random number
83+
*/
84+
static double random_uniform( const double min, const double max ) {
85+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
86+
return min + ( v * ( max - min ) );
87+
}
88+
7789
/**
7890
* Runs a benchmark.
7991
*
@@ -88,9 +100,8 @@ static double benchmark( void ) {
88100
int i;
89101

90102
for ( i = 0; i < 100; i++ ) {
91-
92-
r[ i ] = (double)rand() / ( (double)RAND_MAX + 1.0 );
93-
p[ i ] = (double)rand() / ( (double)RAND_MAX + 1.0 );
103+
r[ i ] = random_uniform( 0.0, 1.0 );
104+
p[ i ] = random_uniform( 0.0, 1.0 );
94105
}
95106

96107
t = tic();

0 commit comments

Comments
 (0)