Skip to content

Commit 28b05e8

Browse files
committed
bench: use random_uniform
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 8155509 commit 28b05e8

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

lib/node_modules/@stdlib/math/base/special/cphasef/benchmark/c/benchmark.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,15 @@ static double tic( void ) {
7474
}
7575

7676
/**
77-
* Generates a random number on the interval [0,1).
77+
* Generates a random number on the interval [min,max).
7878
*
79-
* @return random number
79+
* @param min minimum value (inclusive)
80+
* @param max maximum value (exclusive)
81+
* @return random number
8082
*/
81-
static float rand_float( void ) {
82-
int r = rand();
83-
return (float)r / ( (float)RAND_MAX + 1.0f );
83+
static float random_uniform( const float min, const float max ) {
84+
float v = (float)rand() / ( (float)RAND_MAX + 1.0f );
85+
return min + ( v*(max-min) );
8486
}
8587

8688
/**
@@ -97,8 +99,8 @@ static double benchmark( void ) {
9799
int i;
98100

99101
for ( i = 0; i < 100; i++ ) {
100-
re[ i ] = ( 1000.0f*rand_float() ) - 500.0f;
101-
im[ i ] = ( 1000.0f*rand_float() ) - 500.0f;
102+
re[ i ] = random_uniform( -500.0f, 500.0f );
103+
im[ i ] = random_uniform( -500.0f, 500.0f );
102104
}
103105

104106
t = tic();

lib/node_modules/@stdlib/math/base/special/cphasef/benchmark/c/native/benchmark.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,15 @@ static double tic( void ) {
7777
}
7878

7979
/**
80-
* Generates a random number on the interval [0,1).
80+
* Generates a random number on the interval [min,max).
8181
*
82-
* @return random number
82+
* @param min minimum value (inclusive)
83+
* @param max maximum value (exclusive)
84+
* @return random number
8385
*/
84-
static float rand_float( void ) {
85-
int r = rand();
86-
return (float)r / ( (float)RAND_MAX + 1.0f );
86+
static float random_uniform( const float min, const float max ) {
87+
float v = (float)rand() / ( (float)RAND_MAX + 1.0f );
88+
return min + ( v*(max-min) );
8789
}
8890

8991
/**
@@ -102,8 +104,8 @@ static double benchmark( void ) {
102104
stdlib_complex64_t z;
103105

104106
for ( i = 0; i < 100; i++ ) {
105-
re[ i ] = ( 1000.0f*rand_float() ) - 500.0f;
106-
im[ i ] = ( 1000.0f*rand_float() ) - 500.0f;
107+
re[ i ] = random_uniform( -500.0f, 500.0f );
108+
im[ i ] = random_uniform( -500.0f, 500.0f );
107109
}
108110

109111
t = tic();

0 commit comments

Comments
 (0)