From c7298f7da6a42c047d0d78b19ed8bc1a428f7fd5 Mon Sep 17 00:00:00 2001 From: Joel Therrien Date: Wed, 4 Jul 2018 12:18:27 -0700 Subject: [PATCH] Fix incorrect use of non-concurrent Random object in NumericCovariate. --- .../java/ca/joeltherrien/randomforest/NumericCovariate.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/ca/joeltherrien/randomforest/NumericCovariate.java b/src/main/java/ca/joeltherrien/randomforest/NumericCovariate.java index 5d1c8dc..b9be60a 100644 --- a/src/main/java/ca/joeltherrien/randomforest/NumericCovariate.java +++ b/src/main/java/ca/joeltherrien/randomforest/NumericCovariate.java @@ -17,18 +17,20 @@ public class NumericCovariate implements Covariate{ @Override public Collection generateSplitRules(List> data, int number) { + final Random random = ThreadLocalRandom.current(); + // for this implementation we need to shuffle the data final List> shuffledData; if(number > data.size()){ shuffledData = new ArrayList<>(data); - Collections.shuffle(shuffledData); + Collections.shuffle(shuffledData, random); } else{ // only need the top number entries shuffledData = new ArrayList<>(number); final Set indexesToUse = new HashSet<>(); while(indexesToUse.size() < number){ - final int index = ThreadLocalRandom.current().nextInt(data.size()); + final int index = random.nextInt(data.size()); if(indexesToUse.add(index)){ shuffledData.add(data.get(index));