Randomizing return and doubling array size
<p>I currently have this piece of code.</p>

<p>Currently what happens is that two arrays are being taken in, and all possible sequential combinations of the indices of Array A are being stored as a list of seperate arrays, each of which are the same size as array B. Currently to do this sizeA has to be smaller than sizeB.</p>

<pre><code>import java.util.*;


public class Main {

public static void main(final String[] args) throws FileNotFoundException {

    ArrayList&lt;String&gt; storeB= new ArrayList();
    ArrayList&lt;String&gt; storeA = new ArrayList();

    Scanner scannerB = new Scanner(new File("fileB"));
    Scanner scannerA = new Scanner(new File("fileA"));

    while(scannerB.hasNext()) {
        String b = scannerB.next();{
            storeB.add(b);

        }           
    }



    while(scannerA.hasNext()) {
        String A = scannerA.next();{
            storeA.add(A);              

        }

    }           

    final int sizeA = storeA.size();
    final int sizeB = storeB.size();


    final List&lt;int[]&gt; combinations = getOrderings(sizeA-1, sizeB);


    for(final int[] combo : combinations) {

        for(final int value : combo) {
            System.out.print(value + " ");
        }
        System.out.println();

    }

}

private static List&lt;int[]&gt; getOrderings(final int maxIndex, final int size) {


    final List&lt;int[]&gt; result = new ArrayList&lt;int[]&gt;();

    if(maxIndex == 0) {
        final int[] array = new int[size];
        Arrays.fill(array, maxIndex);
        result.add(array);
        return result;
    }

        // creating an array for each occurence of maxIndex, and  generating each head 
        //recursively

    for(int i = 1; i &lt; size - maxIndex + 1; ++i) {

        //Generating every possible head for the array
        final List&lt;int[]&gt; heads = getOrderings(maxIndex - 1, size - i);

        //Combining every head with the tail
        for(final int[] head : heads) {
            final int[] array = new int[size];
            System.arraycopy(head, 0, array, 0, head.length);

            //Filling the tail of the array with i maxIndex values
            for(int j = 1; j &lt;= i; ++j)
                array[size - j] = maxIndex;
            result.add(array);
        }

    }

    return result;

}

}
</code></pre>

<p>I'm wondering, regardless  of sizeA and sizeB, how do I modify this to create arrays which are double sizeB and duplicate each index value. So if we had:
    [0,1,1,2] 
this would become:
    [0,0,1,1,1,1,2,2]
i.e duplicating each value and placing it next to it.</p>

<p>Also, how would I eliminate recursion in this so that rather than producing all possible combinations, on each call, a single array at random is produced rather than a list of arrays.</p>

<p>Thank you.</p>
