Java Queue Usage randomizeIndex(char[] array)

Here you can find the source of randomizeIndex(char[] array)

Description

randomize Index

License

Open Source License

Parameter

Parameter Description
array the array to randomize.

Return

an array that is a result of mixing the index values of the first array.

Declaration

private static char[] randomizeIndex(char[] array) 

Method Source Code

//package com.java2s;
/*/*from  w w  w  .jav a2 s .  co m*/
  This file is part of Cuber.
    
Cuber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
    
Cuber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with Cuber.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.ArrayList;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class Main {
    /**
     * @param array
     *            the array to randomize.
     * @return an array that is a result of mixing the index values of the first array.
     * @author wonka
     * @since 23/04/2013
     */
    private static char[] randomizeIndex(char[] array) {
        char[] randomArray = new char[array.length];
        List<Integer> set = new ArrayList<>();
        while (set.size() < array.length) {
            int index = (int) (Math.random() * array.length);
            if (!set.contains(index)) {
                set.add(index);
            }
        }
        Queue<Integer> queue = new LinkedList<>(set);
        int i = 0;
        while (!queue.isEmpty()) {
            randomArray[i++] = array[queue.poll()];
        }
        return randomArray;
    }
}

Related

  1. loadBalancingLeftHeavy(List tasks, int size)
  2. offerUntilSuccess(T entry, Queue queue)
  3. parsePathToStack(String path)
  4. pollWhileNotEmpty(Queue queue)
  5. queue(final Queue queue, final Object o, final Class clazz, final boolean removeNull)
  6. scramble(Object object)
  7. setQueueValue(final Queue queue, final Object obj, final Class clazz, final boolean removeNull)
  8. toArrayTest(Queue q)
  9. transferAllElementsFromListToQueue(final List elements, Queue queue)

  10. HOME | Copyright © www.java2s.com 2016