本文整理汇总了Java中org.apache.commons.lang3.RandomStringUtils.random方法的典型用法代码示例。如果您正苦于以下问题:Java RandomStringUtils.random方法的具体用法?Java RandomStringUtils.random怎么用?Java RandomStringUtils.random使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.lang3.RandomStringUtils
的用法示例。
在下文中一共展示了RandomStringUtils.random方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldThrowAnExceptionIfRequestedTagIsNotFound
import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
@Test
public void shouldThrowAnExceptionIfRequestedTagIsNotFound() throws Exception {
List<Node> testFixtures = nUnitAdapter.extractTestFixtures(nUnitAdapter.extractDocument(sample1Path));
NodeList nodeList = new NodeList() {
@Override
public Node item(int index) {
return testFixtures.get(0);
}
@Override
public int getLength() {
return 1;
}
};
String tagName = RandomStringUtils.random(5);
try {
nUnitAdapter.getNodesByTagName(nodeList, tagName);
fail("No exception was thrown");
} catch (Exception e) {
assertTrue(e.getMessage().equals("Element with tag name: " + tagName + " not found."));
}
}
示例2: shouldWriteConfigurationFile
import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
@Test
public void shouldWriteConfigurationFile() throws IOException {
new ObjectMapper().writeValue(rewritableResourcePath.resolve("config.json").toFile(), defaultConfig);
try {
final JoalConfigProvider provider = new JoalConfigProvider(new ObjectMapper(), rewritableResourcePath.toString(), Mockito.mock(ApplicationEventPublisher.class));
final Random rand = new Random();
final AppConfiguration newConf = new AppConfiguration(
rand.longs(1, 200).findFirst().getAsLong(),
rand.longs(201, 400).findFirst().getAsLong(),
rand.ints(1, 5).findFirst().getAsInt(),
RandomStringUtils.random(60),
false
);
provider.saveNewConf(newConf);
assertThat(provider.loadConfiguration()).isEqualTo(newConf);
} finally {
Files.deleteIfExists(rewritableResourcePath.resolve("config.json"));
}
}
示例3: register
import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
@Transactional
public void register(RequestUserDTO userDTO, String requestURL) {
//ugly workaround to avoid concurrency issues
userRepository.findByUsernameOrEmail(userDTO.getUsername(), userDTO.getEmail())
.ifPresent(user -> {
throw new SBException("username or email already present in the system");
});
final String confirmationCode = RandomStringUtils.random(10, true, true);
User newUser = new User();
newUser.setEmail(userDTO.getEmail());
newUser.setUsername(userDTO.getUsername());
newUser.setPassword(passwordEncoder.encode(userDTO.getPassword()));
newUser.setConfirmationCode(confirmationCode);
newUser.setRole(Role.ROLE_USER);
//TODO - fix this url
String url = Utils.buildURL(requestURL, userDTO.getEmail(), confirmationCode);
emailSender.sendEmail(userDTO, url);
userRepository.save(newUser);
}
示例4: secureRandomAlphanumeric
import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
/**
* Generate a random alphanumeric string using SecureRandom.
*
* @param length the length of the generated string
* @return a random string of the given length
* @see {@link SecureRandom}
*/
public static String secureRandomAlphanumeric(int length) {
return RandomStringUtils.random(
length,
0,
possibleCharacters.length - 1,
false,
false,
possibleCharacters,
new SecureRandom());
}
示例5: rename
import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
/**
* 自定义方式重命名sql文件
* @param fileName 原文件名
* @return 新文件名(当前时间+4位随机数+扩展名:201703091011581104.sql)
*/
public static String rename(String type) {
// 获取4位随机数字符串
String ranStr = RandomStringUtils.random(4, false, true);
// 当前时间字符串
String timeStr = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
return timeStr + ranStr + "." + type;
}
示例6: randomAsciiFixLength
import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
/**
* 随机ASCII字符(含字母,数字及其他符号),固定长度
*/
public static String randomAsciiFixLength(Random random, int length) {
return RandomStringUtils.random(length, 32, 127, false, false, null, random);
}
示例7: randomStringRandomLength
import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
/**
* 随机字母或数字,随机长度
*/
public static String randomStringRandomLength(Random random, int minLength, int maxLength) {
return RandomStringUtils.random(nextInt(random, minLength, maxLength), 0, 0, true, true, null, random);
}
示例8: generateCommitterEmail
import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
private String generateCommitterEmail() {
return RandomStringUtils.random(10, true, true) + "@redhat.com";
}
示例9: randomAsciiRandomLength
import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
/**
* 随机ASCII字符(含字母,数字及其他符号),随机长度
*/
public static String randomAsciiRandomLength(Random random, int minLength, int maxLength) {
return RandomStringUtils.random(nextInt(random, minLength, maxLength), 32, 127, false, false, null, random);
}
示例10: randomAlphaNumericString
import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
private String randomAlphaNumericString() {
int length = random.nextInt(10);
String alphanumerics = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
return RandomStringUtils.random(length, 0, alphanumerics.length(), true, true, alphanumerics.toCharArray(), random);
}
示例11: randomData
import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
private String randomData() {
return RandomStringUtils.random(4096, "abcdefghijklmnopqrstuvwxyz");
}
示例12: registerUserIfNotExist
import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
public String registerUserIfNotExist(User user)
{
String password = RandomStringUtils.random(10, "zvnjfsqw1234567890");
String query = "SELECT * FROM Users WHERE id = ?";
String insertQuery = "INSERT INTO Users (id, firstName, lastName, userName, language, isBot, password) " +
"VALUES (?, ?, ?, ?, ?, ?, ?) " +
"ON CONFLICT (id) DO UPDATE SET " +
"firstName = ?," +
"lastName =?," +
"userName = ?," +
"language = ?";
try
{
StringBuilder stringBuilder = new StringBuilder();
jdbcTemplate.query(query, result ->
{
String pas = result.getString("password");
if (pas != null)
{
stringBuilder.append(pas);
}
}, user.getId());
if (stringBuilder.length() == 0)
{
jdbcTemplate.update(insertQuery,
user.getId(),
user.getFirstName(),
user.getLastName(),
user.getUserName(),
user.getLanguageCode(),
user.getBot(),
password,
user.getFirstName(),
user.getLastName(),
user.getUserName(),
user.getLanguageCode()
);
return password;
}
}
catch (Exception e)
{
logger.error("Error", e);
}
return null;
}
示例13: generateClientId
import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
public static String generateClientId(){
return RandomStringUtils.random(20,true,true);
}
示例14: generateClientSecret
import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
public static String generateClientSecret(){
return RandomStringUtils.random(20, true, true);
}
示例15: randomLetterFixLength
import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
/**
* 随机字母,固定长度
*/
public static String randomLetterFixLength(Random random, int length) {
return RandomStringUtils.random(length, 0, 0, true, false, null, random);
}