Simple code to generate One Time Password.
We are using java.util.SplittableRandom which was introduced in Java 8.
We are using java.util.SplittableRandom which was introduced in Java 8.
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
import java.util.SplittableRandom; | |
public class OTPgenerator { | |
public static void main(String[] p) { | |
int len = 6; | |
if(p.length > 0) { | |
len = Integer.valueOf(p[0]); | |
} | |
StringBuilder sb = new StringBuilder(); | |
SplittableRandom ran = new SplittableRandom(); | |
for(int i =0; i < len; i++) { | |
int n = ran.nextInt(1,10); | |
sb.append(n); | |
} | |
System.out.println(" Gnerated OTP " + sb.toString()); | |
} | |
} |