`Examples/Framework/RandomNumbers::Config::seed` is more like an event offset
https://github.com/acts-project/acts/blob/c175d93b33ffe709f804d82b6e60953866d3c92b/Examples/Framework/src/Framework/RandomNumbers.cpp#L22-L24
I spent some time debugging an issue today that seemed to occur within the first 100 events no matter what I entered as seed value. As one might argue is reasonable, I interpreted seed to cause a complete randomization of all event seeds, but it turns out that it is merely a shift in the sequence of seeds that is generated.
Possible solutions:
m_cfg.seedcan be renamed tom_cfg.eventNumberOffsetto more accurately reflect its function.m_cfg.seedcould be used as seed for a (implementation independent) PRNG, and a random uint drawn from that could be added to the event number.
I agree that is not great. I would lean towards drawing a pseudo random number by combining event number and the seed.
I vaguely remember that we were using cantor pairing to do this in the past. I don't remember when or why we moved away from this.
Overnight I remembered that one can also just hash the seed. That's essentially what gaudi does, if I recall correctly, and what k4FWCore does at https://github.com/key4hep/k4FWCore/blob/main/k4FWCore/components/UniqueIDGenSvc.cpp#L55
@andiwand also effectively suggested using a hash function. @wdconinc do you want to contribute this in a PR? We can backport it to a v39 release if you need it.
Happy to contribute a fix. No need to backport (now that I know the underlying behavior).
I'd implement an approach by simply hashing the m_cfg.seed before adding to event number. The only thing that speaks against a simple std::hash<RandomSeed>(m_cfg.seed) is that std::hash is not implementation-independent (and shudder "some implementations use trivial (identity) hash functions" 1). Do we have better hash functions already in Acts?
I fear std::hash(i) == i usually for integer types. Boost has a hash combine function that could be used to "add" the two numbers together. That would also break the symmetry and mix the numbers better. https://www.boost.org/doc/libs/1_55_0/doc/html/hash/combine.html
This issue/PR has been automatically marked as stale because it has not had recent activity. The stale label will be removed if any interaction occurs.
I'll get to this soon! 😀
This issue/PR has been automatically marked as stale because it has not had recent activity. The stale label will be removed if any interaction occurs.