From 22eeb94052b2d464a900831ae215a5011fceb33b Mon Sep 17 00:00:00 2001 From: RISHAV Date: Mon, 14 Oct 2024 12:08:10 +0530 Subject: [PATCH] fix(random): ensure correct seed initialization with falsy values 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 --- lib/node_modules/@stdlib/random/shuffle/lib/factory.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/random/shuffle/lib/factory.js b/lib/node_modules/@stdlib/random/shuffle/lib/factory.js index 91544cb5ddc..c3154b7313a 100644 --- a/lib/node_modules/@stdlib/random/shuffle/lib/factory.js +++ b/lib/node_modules/@stdlib/random/shuffle/lib/factory.js @@ -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' ); @@ -63,7 +64,7 @@ function factory( config ) { throw err; } } - if ( config && config.seed ) { + if ( config && hasOwnProp( config, 'seed' ) ) { rand = randu({ 'seed': config.seed });