@@ -127,15 +127,55 @@ Bool_t GeneratorHybrid::Init()
127127 addSubGenerator (count, gen);
128128 count++;
129129 }
130+ if (mRandomize ) {
131+ if (std::all_of (mFractions .begin (), mFractions .end (), [](int i) { return i == 1 ; })) {
132+ LOG (info) << " Full randomisation of generators order" ;
133+ } else {
134+ LOG (info) << " Randomisation based on fractions" ;
135+ int allfracs = 0 ;
136+ for (auto & f : mFractions ) {
137+ allfracs += f;
138+ }
139+ // Assign new rng fractions
140+ float sum = 0 ;
141+ float chance = 0 ;
142+ for (int k = 0 ; k < mFractions .size (); k++) {
143+ if (mFractions [k] == 0 ) {
144+ // Generator will not be used if fraction is 0
145+ mRngFractions .push_back (-1 );
146+ LOG (info) << " Generator " << mGens [k] << " will not be used" ;
147+ } else {
148+ chance = static_cast <float >(mFractions [k]) / allfracs;
149+ sum += chance;
150+ mRngFractions .push_back (sum);
151+ LOG (info) << " Generator " << (mConfigs [k] == " " ? mGens [k] : mConfigs [k]) << " has a " << chance * 100 << " % chance of being used" ;
152+ }
153+ }
154+ }
155+ } else {
156+ LOG (info) << " Generators will be used in sequence, following provided fractions" ;
157+ }
130158 return Generator::Init ();
131159}
132160
133161Bool_t GeneratorHybrid::generateEvent ()
134162{
135163 // Order randomisation or sequence of generators
136- // following provided fractions, if not generators are used in proper sequence
164+ // following provided fractions. If not available generators will be used sequentially
137165 if (mRandomize ) {
138- mIndex = gRandom ->Integer (mGens .size ());
166+ if (mRngFractions .size () != 0 ) {
167+ // Generate number between 0 and 1
168+ float rnum = gRandom ->Rndm ();
169+ // Find generator index
170+ for (int k = 0 ; k < mRngFractions .size (); k++) {
171+ if (rnum <= mRngFractions [k]) {
172+ mIndex = k;
173+ break ;
174+ }
175+ }
176+ } else {
177+ mIndex = gRandom ->Integer (mGens .size ());
178+ }
139179 } else {
140180 while (mFractions [mCurrentFraction ] == 0 || mseqCounter == mFractions [mCurrentFraction ]) {
141181 if (mFractions [mCurrentFraction ] != 0 ) {
0 commit comments