As part of my project, I need to create non-repeating 2 or 3 digit random numbers by specifying a set of numbers. I do not want to implement a list or array for this, since I have to get 1 random number for each function call.
I tried to do this using the Java SecureRandom class. I got help from some sites, but I got stuck between them, can we shuffle VALUES and do it? But I do not know how to do this. Can someone help me?
import java.security.SecureRandom;
public class RandomNumber {
private static final RandomNumber rnd= new RandomNumber();
private static final char[] VALUES = new char[] {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
private static final SecureRandom srn= new SecureRandom();
public String createID()
{
byte[] bytes = new byte[3];
srn.nextBytes(bytes);
}
source
share