当前位置: 首页>>代码示例>>Java>>正文


Java RandomStringUtils.random方法代码示例

本文整理汇总了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."));
    }
}
 
开发者ID:DonutReport,项目名称:donut-nunit-adapter,代码行数:24,代码来源:NUnitAdapterTest.java

示例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"));
    }
}
 
开发者ID:anthonyraymond,项目名称:joal,代码行数:22,代码来源:JoalConfigProviderTest.java

示例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);
}
 
开发者ID:egch,项目名称:sushi-bar-BE,代码行数:23,代码来源:RegistrationBO.java

示例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());
}
 
开发者ID:3wks,项目名称:generator-thundr-gae-react,代码行数:18,代码来源:RandomUtil.java

示例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;
}
 
开发者ID:ranji1221,项目名称:clemon,代码行数:13,代码来源:BackupUtil.java

示例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);
}
 
开发者ID:zhangjunfang,项目名称:util,代码行数:7,代码来源:RandomUtil.java

示例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);
}
 
开发者ID:zhangjunfang,项目名称:util,代码行数:7,代码来源:RandomUtil.java

示例8: generateCommitterEmail

import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
private String generateCommitterEmail() {
    return RandomStringUtils.random(10, true, true) + "@redhat.com";
}
 
开发者ID:redhat-developer,项目名称:che-starter,代码行数:4,代码来源:WorkspacePreferencesClientTest.java

示例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);
}
 
开发者ID:zhangjunfang,项目名称:util,代码行数:7,代码来源:RandomUtil.java

示例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);
}
 
开发者ID:dizitart,项目名称:nitrite-database,代码行数:6,代码来源:Generator.java

示例11: randomData

import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
private String randomData() {
    return RandomStringUtils.random(4096, "abcdefghijklmnopqrstuvwxyz");
}
 
开发者ID:Sixt,项目名称:ja-micro,代码行数:4,代码来源:KafkaThrottlingTest.java

示例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;
}
 
开发者ID:AnatoliyKozlov,项目名称:YouTrends,代码行数:53,代码来源:UserDAO.java

示例13: generateClientId

import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
public static String generateClientId(){
	return RandomStringUtils.random(20,true,true);
}
 
开发者ID:ranji1221,项目名称:clemon,代码行数:4,代码来源:GuidUtil.java

示例14: generateClientSecret

import org.apache.commons.lang3.RandomStringUtils; //导入方法依赖的package包/类
public static String generateClientSecret(){
	return RandomStringUtils.random(20, true, true);
}
 
开发者ID:ranji1221,项目名称:clemon,代码行数:4,代码来源:GuidUtil.java

示例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);
}
 
开发者ID:zhangjunfang,项目名称:util,代码行数:7,代码来源:RandomUtil.java


注:本文中的org.apache.commons.lang3.RandomStringUtils.random方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。