當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。