Skip to content

Commit 3de0f0e

Browse files
fix: added function to get random numbers
1 parent decf75f commit 3de0f0e

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

lib/node_modules/@stdlib/stats/base/dists/uniform/mean/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2024 The Stdlib Authors.
5+
Copyright (c) 2018 The Stdlib Authors.
66
77
Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.
@@ -210,7 +210,7 @@ int main( void ) {
210210
a = (double)( rand() % 10 );
211211
b = a + (double)( rand() % 10 + 1 ); // ensure b > a
212212
y = stdlib_base_dists_uniform_mean( a, b );
213-
printf( "a: %lf, b: %lf, Mean(X;a,b): %lf\n", a, b, y );
213+
printf( "a: %lf, b: %lf, E(X;a,b): %lf\n", a, b, y );
214214
}
215215
}
216216
```

lib/node_modules/@stdlib/stats/base/dists/uniform/mean/benchmark/benchmark.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2024 The Stdlib Authors.
4+
* Copyright (c) 2018 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.

lib/node_modules/@stdlib/stats/base/dists/uniform/mean/benchmark/c/benchmark.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ static void print_version( void ) {
3737
/**
3838
* Prints the TAP summary.
3939
*
40-
* @param total total number of tests
41-
* @param passing total number of passing tests
40+
* @param total total number of tests
41+
* @param passing total number of passing tests
4242
*/
4343
static void print_summary( int total, int passing ) {
4444
printf( "#\n" );
@@ -52,7 +52,7 @@ static void print_summary( int total, int passing ) {
5252
/**
5353
* Prints benchmarks results.
5454
*
55-
* @param elapsed elapsed time in seconds
55+
* @param elapsed elapsed time in seconds
5656
*/
5757
static void print_results( double elapsed ) {
5858
double rate = (double)ITERATIONS / elapsed;
@@ -74,23 +74,39 @@ 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
*
8092
* @return elapsed time in seconds
8193
*/
8294
static double benchmark( void ) {
8395
double elapsed;
84-
double a, b;
96+
double a[ 100 ];
97+
double b[ 100 ];
8598
double y;
8699
double t;
87100
int i;
88101

102+
for ( i = 0; i < 100; i++ ) {
103+
a[ i ] = random_uniform( 0.0, 10.0 );
104+
b[ i ] = random_uniform( a[ i ], 20.0 );
105+
}
106+
89107
t = tic();
90108
for ( i = 0; i < ITERATIONS; i++ ) {
91-
a = ( (double)rand() / (double)RAND_MAX ) * 100.0; // Random lower bound between 0 and 100
92-
b = a + ( (double)rand() / (double)RAND_MAX ) * 100.0; // Random upper bound greater than a
93-
y = stdlib_base_dists_uniform_mean( a, b );
109+
y = stdlib_base_dists_uniform_mean( a[ i%100 ], b[ i%100 ] );
94110
if ( y != y ) {
95111
printf( "should not return NaN\n" );
96112
break;

lib/node_modules/@stdlib/stats/base/dists/uniform/mean/examples/c/example.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,20 @@
2020
#include <stdlib.h>
2121
#include <stdio.h>
2222

23+
static double random_uniform( const double min, const double max ) {
24+
double v = (double)rand() / ( (double)RAND_MAX + 1.0 );
25+
return min + ( v*(max-min) );
26+
}
27+
2328
int main( void ) {
2429
double a;
2530
double b;
2631
double y;
2732
int i;
2833

2934
for ( i = 0; i < 25; i++ ) {
30-
a = (double)rand() / ( (double)RAND_MAX + 1.0 ) * 100.0;
31-
b = a + ( (double)rand() / ( (double)RAND_MAX + 1.0 ) * 50.0 );
35+
a = random_uniform( 0.0, 10.0 );
36+
b = random_uniform( a, 20.0 );
3237
y = stdlib_base_dists_uniform_mean( a, b );
3338
printf( "a: %lf , b: %lf , Mean: %lf\n", a, b, y );
3439
}

0 commit comments

Comments
 (0)