Skip to content

Commit

Permalink
fix(random): ensure correct seed initialization with falsy values
Browse files Browse the repository at this point in the history
The previous implementation used a direct property check (`config.seed`),
which could inadvertently treat falsy values like `0` as missing, leading
to incorrect random seed initialization.

Changed the condition to explicitly check for the presence of the `seed`
property using `Object.prototype.hasOwnProperty.call()`. This update
ensures that seed initialization handles falsy but valid seed values
correctly.

Resolves #2952.

This pull request addresses the bug where setting `seed=0` leads to
non-deterministic behavior.

No related issues.

No questions for reviewers.

No additional information relevant to this pull request.

- [x] Read, understood, and followed the [contributing guidelines][contributing].

---

@stdlib-js/reviewers

[contributing]: https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md
  • Loading branch information
rishav2404 committed Oct 14, 2024
1 parent 3282bd0 commit 22eeb94
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/node_modules/@stdlib/random/shuffle/lib/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var deepCopy = require( '@stdlib/utils/copy' );
var floor = require( '@stdlib/math/base/special/floor' );
var randu = require( '@stdlib/random/base/mt19937' ).factory;
var format = require( '@stdlib/string/format' );
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
var defaults = require( './defaults.json' );
var validate = require( './validate.js' );

Expand Down Expand Up @@ -63,7 +64,7 @@ function factory( config ) {
throw err;
}
}
if ( config && config.seed ) {
if ( config && hasOwnProp( config, 'seed' ) ) {
rand = randu({
'seed': config.seed
});
Expand Down

0 comments on commit 22eeb94

Please sign in to comment.