title: how to create a random generated alphabet in Java
body: <p>Looking to create a randomly generated alphabet for a substitution cipher. My idea was something like this.</p>
  
  <pre><code>        char randomChar = (char) (97 + r.nextInt(25));
  </code></pre>
  
  <p>However this will cause repetition of letters. Going through the char array and seeing if the letter is already present seems inefficient also.</p>
  
  <p>edit: I was too vague in my request and see this now. Here is the full question I am trying to solve. The alphabet must also contain the space button character e.g ' '.</p>
  
  <blockquote>
    <p>Write a Java program which converts (user entered) plain text to cipher text using a substitution cipher (in which plain text letters are randomly assigned to cipher text letters).  Note that a Substitution Cipher replaces plaintext with cipher-text. The most common substitution ciphers replace single characters of plaintext with predefined single characters of cipher-text (e.g. the plain-text character `a' might be replaced by cipher text character 'q', 'b' might be replaced by 'x', 'c' by 'k' and so on).  Each plain-text character should be replaced by a different cipher-text character.
    As part of your solution you must write and use at least the following functions/methods:
    (i)    createCipher() which determines and returns the mapping from plain text to cipher text.  Each plain text character ('a' .. 'z', ' ') must be randomly assigned a cipher-text character;</p>
  </blockquote>