diff options
Diffstat (limited to 'src/com/isode/stroke/base')
-rw-r--r-- | src/com/isode/stroke/base/JavaRandomGenerator.java | 31 | ||||
-rw-r--r-- | src/com/isode/stroke/base/RandomGenerator.java | 23 |
2 files changed, 54 insertions, 0 deletions
diff --git a/src/com/isode/stroke/base/JavaRandomGenerator.java b/src/com/isode/stroke/base/JavaRandomGenerator.java new file mode 100644 index 0000000..09d389d --- /dev/null +++ b/src/com/isode/stroke/base/JavaRandomGenerator.java @@ -0,0 +1,31 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.base; + +import java.util.Random; + +/** + * A {@link RandomGenerator} that generates integers with a uniform + * distribution (using the java {@link Random} class). + */ +public final class JavaRandomGenerator implements RandomGenerator { + + /** + * {@link Random} to use to generate the numbers + */ + private final Random rng = new Random(); + + @Override + public int generateRandomInteger(int max) { + // Random.nextInt(bound) is exclusive of bound + return rng.nextInt(max+1); + } + +} diff --git a/src/com/isode/stroke/base/RandomGenerator.java b/src/com/isode/stroke/base/RandomGenerator.java new file mode 100644 index 0000000..970bb98 --- /dev/null +++ b/src/com/isode/stroke/base/RandomGenerator.java @@ -0,0 +1,23 @@ +/* Copyright (c) 2016, Isode Limited, London, England. + * All rights reserved. + * + * Acquisition and use of this software and related materials for any + * purpose requires a written license agreement from Isode Limited, + * or a written license from an organisation licensed by Isode Limited + * to grant such a license. + * + */ +package com.isode.stroke.base; + +public interface RandomGenerator { + + /** + * Generates a random integer between 0 and 'max', + * 'max' inclusive. + * @param max The maximum possible value + * to generate (inclusive) + * @return A random integer between 0 and 'max' + */ + public int generateRandomInteger(int max); + +} |