Last active
August 19, 2016 08:45
-
-
Save rynr/eddae60085eace987c3318a3d9437e83 to your computer and use it in GitHub Desktop.
TestHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.rjung.tools.testing; | |
import java.math.BigInteger; | |
import java.security.SecureRandom; | |
public class TestHelper { | |
private static final int DEFAULT_STRING_LENGTH = 8; | |
private static final int DEFAULT_MAX_INT = 255; | |
private static SecureRandom random; | |
public static String getRandomString() { | |
return getRandomString(DEFAULT_STRING_LENGTH); | |
} | |
public static String getRandomString(int length) { | |
return new BigInteger(length * 5, getRandom()).toString(32); | |
} | |
public static int getRandomInt() { | |
return getRandomInt(DEFAULT_MAX_INT); | |
} | |
public static int getRandomInt(int max) { | |
return getRandomInt(0, max); | |
} | |
public static int getRandomInt(int min, int max) { | |
return getRandom().nextInt((max - min) + 1) + min; | |
} | |
private static SecureRandom getRandom() { | |
if (random == null) { | |
random = new SecureRandom(); | |
} | |
return random; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment