workItem(TUP-21307):Duplicate code in IdGenerator + TalendString (#2193)
* workItem(TUP-21307):Duplicate code in IdGenerator + TalendString https://jira.talendforge.org/browse/TUP-21307 * workItem(TUP-21307):Duplicate code in IdGenerator + TalendString https://jira.talendforge.org/browse/TUP-21307 * workItem(TUP-21307):Use SecureRandom + StringBuilder in IdGenerator + TalendString https://jira.talendforge.org/browse/TUP-21307
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
// ============================================================================
|
||||
package routines;
|
||||
|
||||
import java.util.Random;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Vector;
|
||||
|
||||
public class TalendString {
|
||||
@@ -74,20 +74,20 @@ public class TalendString {
|
||||
* {example} getAsciiRandomString(6) # Art34Z
|
||||
*/
|
||||
public static String getAsciiRandomString(int length) {
|
||||
Random random = new Random();
|
||||
SecureRandom random = new SecureRandom();
|
||||
int cnt = 0;
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
char ch;
|
||||
int end = 'z' + 1;
|
||||
int start = ' ';
|
||||
while (cnt < length) {
|
||||
ch = (char) (random.nextInt(end - start) + start);
|
||||
if (Character.isLetterOrDigit(ch)) {
|
||||
buffer.append(ch);
|
||||
builder.append(ch);
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
return buffer.toString();
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user