title: Function to generate a random password
body: <p>I want to generate a random password for employees with the function below. This is my first attempt with functions in R. So I need a bit help.</p>
  
  <pre><code>genPsw &lt;- function(num, len=8) {
            # Vorgaben für die Passwortkonventionen festlegen
              myArr  &lt;- c("", 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", 
                          "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", 
                          "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", 
                          "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o",
                          "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", 
                          "!", "§", "$", "%", "&amp;", "(", ")", "*")
            # replicate is a wrapper for the common use of sapply for repeated evaluation of an expression 
            # (which will usually involve random number generation).
              replicate(num, paste(sample(myArr, size=len, replace=T), collapse=""))
            # nrow of dataframe mitarbeiter 
            dim_mitarbeiter &lt;- nrow(mitarbeiter)
            for(i in 1:dim_mitarbeiter) {
                          # Random Number Generation with i
                            set.seed(i)
                          # Generate Passwort for new variable password
                          mitarbeiter$passwort &lt;- genPsw(i)                
            }
  
  }
  </code></pre>
  
  <p>With the answer form Floo0 I've changed the function to somthing like that, but it doesn't work:</p>
  
  <pre><code>genPsw &lt;- function(num, len=8) {
            # Vorgaben für die Passwortkonventionen festlegen
            sam&lt;-list()
            sam[[1]]&lt;-1:9
            sam[[2]]&lt;-letters
            sam[[3]]&lt;-LETTERS
            sam[[4]]&lt;-c("!", "§", "$", "%", "&amp;", "(", ")", "*")
  
            # nrow of dataframe mitarbeiter 
            dim_mitarbeiter &lt;- nrow(mitarbeiter)
            for(i in 1:dim_mitarbeiter) {
                          # Random Number Generation with i
                              tmp&lt;-mapply(sample,sam,c(2,2,2,2))
                           # Generate Passwort for new variable password
                          mitarbeiter$passwort &lt;- paste(sample(tmp),collapse="")
            }
  
  }
  </code></pre>