From e26d42a906852250b7e054aca445881d7ddb4159 Mon Sep 17 00:00:00 2001 From: dyzheng Date: Thu, 26 Mar 2026 22:53:19 +0800 Subject: [PATCH] Refactor: Replace magic number and C-style cast in sto_wf.cpp --- source/source_pw/module_stodft/sto_wf.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/source_pw/module_stodft/sto_wf.cpp b/source/source_pw/module_stodft/sto_wf.cpp index e844503a11..3f0438496a 100644 --- a/source/source_pw/module_stodft/sto_wf.cpp +++ b/source/source_pw/module_stodft/sto_wf.cpp @@ -66,13 +66,15 @@ void Stochastic_WF::clean_chiallorder() template void Stochastic_WF::init_sto_orbitals(const int seed_in) { + const unsigned int RANK_SEED_FACTOR = 10000; // 用于区分不同进程/组的随机种子偏移量 + if (seed_in == 0 || seed_in == -1) { - srand((unsigned)time(nullptr) + GlobalV::MY_RANK * 10000); // GlobalV global variables are reserved + srand(static_cast(time(nullptr)) + GlobalV::MY_RANK * RANK_SEED_FACTOR); } else { - srand((unsigned)std::abs(seed_in) + (GlobalV::MY_BNDGROUP * GlobalV::NPROC_IN_BNDGROUP + GlobalV::RANK_IN_BPGROUP) * 10000); + srand(static_cast(std::abs(seed_in)) + (GlobalV::MY_BNDGROUP * GlobalV::NPROC_IN_BNDGROUP + GlobalV::RANK_IN_BPGROUP) * RANK_SEED_FACTOR); } this->allocate_chi0();