diff --git a/src/modules/common/moduleRandom.f90 b/src/modules/common/moduleRandom.f90 index cd553a8..3fbf5c8 100644 --- a/src/modules/common/moduleRandom.f90 +++ b/src/modules/common/moduleRandom.f90 @@ -73,10 +73,21 @@ MODULE moduleRandom REAL(8), INTENT(in):: cumWeight(1:) REAL(8), INTENT(in):: sumWeight REAL(8):: rnd0b - INTEGER:: rnd + INTEGER:: rnd, i rnd0b = random(0.D0, sumWeight) - rnd = MINLOC(DABS(rnd0b - cumWeight), 1) + i = 1 + DO + IF (rnd0b <= cumWeight(i)) THEN + rnd = i + EXIT + + ELSE + i = i +1 + + END IF + END DO + ! rnd = MINLOC(DABS(rnd0b - cumWeight), 1) END FUNCTION randomWeighted