Skip to content

Commit aab2702

Browse files
committed
Refined seeding
1 parent fb5b8f5 commit aab2702

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

MC/config/PWGUD/external/generator/GeneratorStarlight.C

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,23 @@ R__ADD_INCLUDE_PATH($STARlight_ROOT/include)
1111

1212
// usage: o2-sim -g external --configKeyValues 'GeneratorExternal.fileName=GeneratorStarlight.C;GeneratorExternal.funcName=GeneratorStarlight("kCohJpsiToMu")'
1313

14+
unsigned int generateRandomSeed() {
15+
// Use high-resolution clock for time-based seed
16+
auto timeNow = std::chrono::high_resolution_clock::now();
17+
auto timeSeed = static_cast<unsigned int>(timeNow.time_since_epoch().count());
18+
19+
// Random device for system entropy
20+
std::random_device rd;
21+
22+
// Add process ID and thread ID for additional entropy
23+
unsigned int pid = static_cast<unsigned int>(getpid());
24+
unsigned int tid = static_cast<unsigned int>(std::hash<std::thread::id>()(std::this_thread::get_id()));
25+
26+
// Combine all entropy sources
27+
unsigned int seed = timeSeed ^ (rd() << 1) ^ (pid << 2) ^ (tid << 3);
28+
return seed;
29+
}
30+
1431
namespace o2
1532
{
1633
namespace eventgen
@@ -128,12 +145,9 @@ class GeneratorStarlight_class : public Generator
128145

129146
mPdgMother = slConfig[idx].pdg_mother;
130147
mDecayEvtGen = slConfig[idx].decay_EvtGen;
131-
132-
uint random_seed;
133-
unsigned long long int random_value = 0;
134-
ifstream urandom("/dev/urandom", ios::in|ios::binary);
135-
urandom.read(reinterpret_cast<char*>(&random_value), sizeof(random_seed));
136-
148+
149+
unsigned int random_seed = generateRandomSeed();
150+
137151
setParameter(Form("BEAM_1_Z = %3i #Z of target",targZ));
138152
setParameter(Form("BEAM_1_A = %3i #A of target",targA));
139153
setParameter(Form("BEAM_2_Z = %3i #Z of projectile",projZ));
@@ -321,8 +335,7 @@ FairGenerator*
321335
system(TString::Format("cp %s ./my.input",dpmjetconf.c_str()));
322336

323337
//Reset four seeds of the DPMJET random generator in the config
324-
std::random_device rd;
325-
std::mt19937 gen(rd());
338+
std::mt19937 gen(generateRandomSeed());
326339
std::uniform_int_distribution<> dist(1, 168);
327340

328341
std::string command = "awk -i inplace -v nums=\"";

0 commit comments

Comments
 (0)