title: Random sample from column of ArrayType Pyspark
body: <p>I've a column in a Pyspark dataframe with a structure like</p>
  
  <pre><code>Column1
  [a,b,c,d,e]
  [c,b,d,f,g,h,i,p,l,m]
  </code></pre>
  
  <p>I'd like to return another column with a random selection of each array in each row, the amount specified in the function.</p>
  
  <p>So something like <code>data.withColumn("sample", SOME_FUNCTION("column1", 5))</code> returning:</p>
  
  <pre><code>sample
  [a,b,c,d,e]
  [c,b,h,i,p]
  </code></pre>
  
  <p>Hopefully avoiding a python UDF, feel like there should be a function available??</p>
  
  <p>This works: </p>
  
  <pre><code>import random
  def random_sample(population):
      return(random.sample(population, 5))
  
  udf_random = F.udf(random_sample, T.ArrayType(T.StringType()))
  df.withColumn("sample", udf_random("column1")).show()
  </code></pre>
  
  <p>But as I said, it would be good to avoid a UDF.</p>