diff --git a/include/xgboost/generic_parameters.h b/include/xgboost/generic_parameters.h index 7713d6b2b0f7..752342b9a90c 100644 --- a/include/xgboost/generic_parameters.h +++ b/include/xgboost/generic_parameters.h @@ -17,7 +17,7 @@ struct GenericParameter : public XGBoostParameter { public: // stored random seed - int seed; + int64_t seed; // whether seed the PRNG each iteration bool seed_per_iteration; // number of threads to use if OpenMP is enabled diff --git a/tests/cpp/test_learner.cc b/tests/cpp/test_learner.cc index 4216e6e0b6d0..a69fce19d900 100644 --- a/tests/cpp/test_learner.cc +++ b/tests/cpp/test_learner.cc @@ -260,4 +260,26 @@ TEST(Learner, GPUConfiguration) { } } #endif // defined(XGBOOST_USE_CUDA) + +TEST(Learner, Seed) { + auto m = RandomDataGenerator{10, 10, 0}.GenerateDMatrix(); + std::unique_ptr learner { + Learner::Create({m}) + }; + auto seed = std::numeric_limits::max(); + learner->SetParam("seed", std::to_string(seed)); + learner->Configure(); + Json config { Object() }; + learner->SaveConfig(&config); + ASSERT_EQ(std::to_string(seed), + get(config["learner"]["generic_param"]["seed"])); + + seed = std::numeric_limits::min(); + learner->SetParam("seed", std::to_string(seed)); + learner->Configure(); + learner->SaveConfig(&config); + ASSERT_EQ(std::to_string(seed), + get(config["learner"]["generic_param"]["seed"])); +} + } // namespace xgboost