jeudi 17 décembre 2015

Randomizing a string in Java

I need to, using an already defined set of 2-4 letters, create a string that is completely randomized. How would one take letters, combine them into one string, randomize the position of each character and then turn that large string into two randomly sized (but >= 2) other strings. Thanks for everyone's help.

My code so far is:

    //shuffles letters
    ArrayList arrayList = new ArrayList();
    arrayList.add(fromFirst);
    arrayList.add(fromLast);
    arrayList.add(fromCity);
    arrayList.add(fromSong);

    Collections.shuffle(arrayList);

But I found that this shuffles the Strings and not the individual letters. It also, being an array, has the brackets that wouldn't be found in regular writing and I do want it to look like a randomish assortment of letters




Aucun commentaire:

Enregistrer un commentaire