mardi 30 décembre 2014

How to get rid of letters randomly generated after being used?

I'm currently writing a program that requires me to generate random letters from the alphabet and assign them to other letters. (It's an encryption program). The problem is, once I've generated the first few letters, some are generated again.


For example, I want to let a = c (randomly generated letter) But now that c is used, I don't want the other 25 letters to be equal to c. So I don't want b = c I don't know how to go about this as it seems easy enough but I can't manage to do it.


Here is that bit of my code.



for (int i = 0; i<26; i++)
{
Random r = new Random();
cipherArray[i] =(char)(cipherText.charAt(r.nextInt(cipherText.length())));
}
return cipherArray;


Any help is appreciated, thank you.





Aucun commentaire:

Enregistrer un commentaire