org.apache.commons.lang3.ArrayUtils#shuffle ( )源码实例Demo

下面列出了org.apache.commons.lang3.ArrayUtils#shuffle ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Setup
public void setup() {
	int size = 16;
	keys = new byte[size];
	toLookup = new byte[size];

	limits = new int[size];
	for (int i = 0; i < limits.length; i++) {
		ThreadLocalRandom.current().nextInt(0, size + 1);
	}

	ThreadLocalRandom.current().nextBytes(keys);
	Arrays.sort(keys);
	System.arraycopy(keys, 0, toLookup, 0, keys.length);
	ArrayUtils.shuffle(toLookup);
}
 
源代码2 项目: neodymium-library   文件: DataUtils.java
/**
 * A random password that is strong enough for most services
 *
 * @return a password
 */
public static String randomPassword()
{
    final String upper = new RandomStringGenerator.Builder().selectFrom("abcdefghijklmnopqrstuvwxyz".toUpperCase().toCharArray()).build()
                                                            .generate(Neodymium.configuration().dataUtilsPasswordUppercaseCharAmount());

    final String lower = new RandomStringGenerator.Builder().selectFrom("abcdefghijklmnopqrstuvwxyz".toCharArray()).build()
                                                            .generate(Neodymium.configuration().dataUtilsPasswordLowercaseCharAmount());

    final String number = new RandomStringGenerator.Builder().selectFrom("0123456789".toCharArray()).build()
                                                             .generate(Neodymium.configuration().dataUtilsPasswordDigitAmount());

    final String special = new RandomStringGenerator.Builder().selectFrom(Neodymium.configuration().dataUtilsPasswordSpecialChars().toCharArray()).build()
                                                              .generate(Neodymium.configuration().dataUtilsPasswordSpecialCharAmount());

    final char[] all = (upper + lower + number + special).toCharArray();
    ArrayUtils.shuffle(all);

    return new String(all);
}
 
源代码3 项目: basic-tools   文件: Randoms.java
/**
 * max 如果是5 返回[0,1,2,3,4]的随机组合
 * @param max
 * @return
 */
public static int [] getRandomArray(int max){
    //循环遍历队列,这个地方不能每次都按照从0 到 ConstantValue.MemberShipPassivityListCount 大小循环
    //万一数据多了,0 1 2这几个队列没关系,后边的队列会一直处于饥饿状态的,所以每次随机一下
    int[] array = new int[max];
    for(int i = 0;i < max;i++){
        array[i] = i;
    }
    ArrayUtils.shuffle(array);
    return array;
}
 
@Setup
public void setup() {
	int size = 4;
	keys = new byte[size];
	toLookup = new byte[size];
	ThreadLocalRandom.current().nextBytes(keys);
	Arrays.sort(keys);
	System.arraycopy(keys, 0, toLookup, 0, keys.length);
	ArrayUtils.shuffle(toLookup);
}
 
@Setup
public void setup() {
	int size = 16;
	keys = new byte[size];
	toLookup = new byte[size];
	ThreadLocalRandom.current().nextBytes(keys);
	Arrays.sort(keys);
	System.arraycopy(keys, 0, toLookup, 0, keys.length);
	ArrayUtils.shuffle(toLookup);
}
 
@Setup
public void setup() {
	keys = new byte[size];
	toLookup = new byte[size];
	ThreadLocalRandom.current().nextBytes(keys);
	Arrays.sort(keys);
	System.arraycopy(keys, 0, toLookup, 0, keys.length);
	ArrayUtils.shuffle(toLookup);
}
 
@Setup
public void setup() {
	keys = new byte[size + 1];
	toLookup = new byte[size];
	ThreadLocalRandom.current().nextBytes(keys);
	Arrays.sort(keys);
	System.arraycopy(keys, 0, toLookup, 0, toLookup.length);
	ArrayUtils.shuffle(toLookup);
}
 
源代码8 项目: tutorials   文件: ArrayOperations.java
public static int[] shuffleIntArray(int[] array) {
    // we create a different array instance for testing purposes
    int[] shuffled = Arrays.copyOf(array, array.length);
    ArrayUtils.shuffle(shuffled);
    return shuffled;
}
 
源代码9 项目: tutorials   文件: ArrayOperations.java
public static <T> T[] shuffleObjectArray(T[] array) {
    // we create a different array instance for testing purposes
    T[] shuffled = Arrays.copyOf(array, array.length);
    ArrayUtils.shuffle(shuffled);
    return shuffled;
}