From 6389c8ba2d090db7cc4b29f4c775f4c18f8395d9 Mon Sep 17 00:00:00 2001 From: JGonzalez Date: Thu, 27 Jun 2024 12:08:08 +0200 Subject: [PATCH] Quick because food Cartesian fixed now --- src/modules/common/moduleRandom.f90 | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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