Skip to content

Commit

Permalink
Adds a method to RandomUtils to draw a random point
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Aug 17, 2021
1 parent a32acc5 commit 20cb960
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions msi.gama.core/src/msi/gama/common/util/RandomUtils.java
Expand Up @@ -12,12 +12,14 @@

import java.math.BigDecimal;
import java.security.SecureRandom;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Random;

import msi.gama.common.interfaces.IKeyword;
import msi.gama.common.preferences.GamaPreferences;
import msi.gama.metamodel.shape.GamaPoint;
import msi.gama.util.random.CellularAutomatonRNG;
import msi.gama.util.random.GamaRNG;
import msi.gama.util.random.JavaRNG;
Expand Down Expand Up @@ -246,9 +248,7 @@ public void shuffleInPlace(final Collection list) {
final Object[] a = list.toArray(new Object[size]);
list.clear();
shuffleInPlace(a);
for (final Object o : a) {
list.add(o);
}
list.addAll(Arrays.asList(a));
}

public <T> void shuffleInPlace(final T[] a) {
Expand Down Expand Up @@ -387,7 +387,7 @@ public static void testDrawRandomValues(final int min, final int max, final int
}
}

private class BitString {
private static class BitString {

private static final int WORD_LENGTH = 32;

Expand Down Expand Up @@ -567,6 +567,13 @@ public boolean oneOf(final boolean[] c) {
return c[between(0, c.length - 1)];
}

public GamaPoint between(final GamaPoint pMin, final GamaPoint pMax, final GamaPoint pStep) {
double x = between(pMin.x, pMax.x, pStep.x);
double y = between(pMin.y, pMax.y, pStep.y);
double z = between(pMin.z, pMax.z, pStep.z);
return new GamaPoint(x, y, z);
}

// public static void main(final String[] args) {
// USE_BITWISE = false;
// RandomUtils r1 = new RandomUtils(1.0, "mersenne1");
Expand Down

0 comments on commit 20cb960

Please sign in to comment.