Example usage for java.util Random nextInt

List of usage examples for java.util Random nextInt

Introduction

In this page you can find the example usage for java.util Random nextInt.

Prototype

public int nextInt(int bound) 

Source Link

Document

Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.

Usage

From source file:Main.java

public static final String encodeInterfereWord(String src) {
    String base = "abcdefghijklmnopqrstuvwxyz0123456789";
    Random random = new Random();
    StringBuffer sb = new StringBuffer();
    int len = base.length();
    for (int index = 0, size = src.length(); index < size; index++) {
        sb.append(base.charAt(random.nextInt(len)));
        sb.append(src.charAt(index));/*from  w  w  w.  ja va  2s.  co  m*/
    }
    sb.append(base.charAt(random.nextInt(len)));
    return sb.toString();
}

From source file:Helpers.HelpersCSV.java

/**
 * Pick random headers//from   ww w  .  j a  va  2  s.  co  m
 *
 * @param headers
 * @return
 */
public static String pickRandomColumn(String[] headers) {
    Random random = new Random();
    int index = random.nextInt(headers.length);
    String randomColumn = headers[index];
    return randomColumn;

}

From source file:nl.enovation.addressbook.jpa.webui.init.DBInit.java

public static void createItems() {
    String group;/*from  w w w.  j a v a 2 s  .  c om*/
    PhoneNumberEntry phoneNumber;
    Random r = new Random(0);

    for (String g : GROUP_NAMES) {
        group = g;

        int amount = r.nextInt(15) + 1;
        for (int i = 0; i < amount; i++) {
            Contact c = new Contact();
            c.setFirstName(FIRST_NAMES[r.nextInt(FIRST_NAMES.length)]);
            c.setLastName(LAST_NAMES[r.nextInt(LAST_NAMES.length)]);
            c.setCity(CITIES[r.nextInt(CITIES.length)]);
            int n = r.nextInt(100000);
            if (n < 10000) {
                n += 10000;
            }
            c.setZipCode("" + n);
            c.setStreet(STREETS[r.nextInt(STREETS.length)]);
            c.setDepartment(group);
            contactRepository.save(c);

            phoneNumber = new PhoneNumberEntry();
            phoneNumber
                    .setPhoneNumber("+358 02 " + r.nextInt(10) + r.nextInt(10) + r.nextInt(10) + r.nextInt(10));
            phoneNumber.setPhoneNumberType(PhoneNumberType.FAX);
            phoneNumber.setContact(c);
            c.getPhoneNumbers().add(phoneNumber);
            phoneNumberEntryRepository.save(phoneNumber);
        }
    }
}

From source file:com.cuebiq.presto.scalar.HashingFunctions.java

@Description("shuffles using a pseudo random algorithm.")
@ScalarFunction//w w  w  .  j  a v a  2  s .  co  m
@SqlType(StandardTypes.VARCHAR)
public static Slice shuffle_string(@SqlType(StandardTypes.VARCHAR) Slice string) {
    String id = string.toStringUtf8();
    Random rnd = new Random(id.charAt(0));
    byte[] bytes = id.getBytes();
    for (int i = bytes.length; i > 1; i--) {
        swap(bytes, i - 1, rnd.nextInt(i));
    }
    return Slices.wrappedBuffer(bytes);

}

From source file:org.softcatala.corrector.LanguageToolRequest.java

static private String GetSessionID() {
    Random rand = new Random();
    int MAX_NUM = 999999;
    int id = rand.nextInt(MAX_NUM);
    return Integer.toString(id);
}

From source file:ezbake.security.EzSecurityITBase.java

@BeforeClass
public static void setUpServerPool() throws Exception {
    Random portChooser = new Random();
    int port = portChooser.nextInt((34999 - 30000) + 1) + 30000;
    int zooPort = portChooser.nextInt((20499 - 20000) + 1) + 20000;

    redisServer = new LocalRedis();

    EzConfiguration ezConfiguration = new EzConfiguration(new ClasspathConfigurationLoader());
    properties = ezConfiguration.getProperties();
    properties.setProperty(EzBakePropertyConstants.REDIS_HOST, "localhost");
    properties.setProperty(EzBakePropertyConstants.REDIS_PORT, Integer.toString(redisServer.getPort()));
    properties.setProperty(EzBakePropertyConstants.ZOOKEEPER_CONNECTION_STRING,
            "localhost:" + String.valueOf(zooPort));
    properties.setProperty(FileUAService.USERS_FILENAME,
            EzSecurityITBase.class.getResource("/users.json").getFile());
    properties.setProperty(EzBakePropertyConstants.EZBAKE_ADMINS_FILE,
            EzSecurityITBase.class.getResource("/admins").getFile());
    properties.setProperty(AdminServiceModule.PUBLISHING, Boolean.TRUE.toString());

    Properties localConfig = new Properties();
    localConfig.putAll(properties);//from   ww w .  ja va 2 s  .c  o  m
    localConfig.setProperty(EzBakePropertyConstants.EZBAKE_CERTIFICATES_DIRECTORY,
            EzSecurityITBase.class.getResource("/pki/server").getFile());
    localConfig.setProperty("storage.directory", folder.getRoot().toString());

    serverPool = new ThriftServerPool(localConfig, port);
    serverPool.startCommonService(new EzSecurityHandler(), EzSecurityServicesConstants.SECURITY_SERVICE_NAME,
            "12345");
    serverPool.startCommonService(new ezbake.groups.service.EzBakeThriftService(),
            EzGroupsConstants.SERVICE_NAME, "12345");

    ServiceDiscoveryClient client = new ServiceDiscoveryClient(
            properties.getProperty(EzBakePropertyConstants.ZOOKEEPER_CONNECTION_STRING));
    client.setSecurityIdForCommonService(AppName, "10000000");
    client.setSecurityIdForApplication(AppName, "10000000");

    properties.setProperty(EzBakePropertyConstants.EZBAKE_CERTIFICATES_DIRECTORY,
            EzSecurityITBase.class.getResource("/pki/client").getFile());
    properties.setProperty(EzBakePropertyConstants.EZBAKE_SECURITY_ID, "10000000");
}

From source file:com.beginner.core.utils.Tools.java

/**
 * ?????//from   w  ww.  j a v  a  2  s  .  com
 * @return int    ???
 * @since       1.0.0
 */
public static int getRandomNum() {
    Random r = new Random();
    return r.nextInt(900000) + 100000;
}

From source file:Main.java

public static void shuffleArray(PointF[] ar, int length) {
    // If running on Java 6 or older, use `new Random()` on RHS
    Random rnd;
    if (Build.VERSION.SDK_INT >= 21)
        rnd = ThreadLocalRandom.current();
    else/*from ww  w.ja  va 2s.co m*/
        rnd = new Random();

    for (int i = length - 1; i > 0; i--) {
        int index = rnd.nextInt(i + 1);
        // Simple swap
        PointF a = ar[index];
        ar[index] = ar[i];
        ar[i] = a;
    }
}

From source file:misc.TestUtils.java

public static String randomString(Set<Character> availableChars, int maxLength, int minLength) {
    char[] chars = toCharArray(availableChars);
    Random random = new Random();
    int len = minLength + random.nextInt(maxLength - minLength + 1);
    return RandomStringUtils.random(len, chars);
}

From source file:Main.java

private static String randomMac1() {
    String chars = "ABCDE0123456789";
    String res = "";
    Random rnd = new Random();
    int leng = chars.length();
    for (int i = 0; i < 17; i++) {
        if (i % 3 == 2) {
            res = res + ":";
        } else {//w w  w. java  2 s.  co  m
            res = res + chars.charAt(rnd.nextInt(leng));
        }

    }
    return res;
}