Thursday, August 21, 2014

Java Method to Generate OTP

      private static String getOTP(int length) {            
           Random r = new Random();            
           char[] dArray = "0123456789".toCharArray();  
           String ret = "" + dArray[ 1 + r.nextInt(8) ];                                
           for(int i=1; i < length; i++) {  
                ret += dArray[ r.nextInt(9) ];  
           }  
           return ret;  
      }  

No comments:

Followers