title: Postgresql: How to copy rows n times (n=value of original column A) and insert "yes" k-times (k=value column B) randomly within the n new rows
body: <p>I have a dataset where information about public toilet buildings was collected. Each building (dataset row) can contain several toilets (see example datatable below)</p>
  
  <p>To analyze the data, I need every toilet as a single geometry with an attribute female yes/no broken: yes/no. It's not important for me to know exactly if the female toilet is broken or a male one.</p>
  
  <p>So what I try to do is to copy each row of my dataset n times ( n=value of column total_number_toilets) and insert randomly k times 'yes'( k=value of column female_toilets) in column female_toilets and i times 'yes' (i= value of column broken_toilets) in column broken_toilets in the n new rows. The data type of each column is string although there are numbers inserted at the moment, so it should not be a problem to insert 'yes' instead of a number into the columns of the copied rows.</p>
  
  <p>Why it is not important to know exactly if the female toilet is broken or not is  that I just need a huge sample dataset for an application. </p>
  
  <p>Original row:</p>
  
  <pre><code>total_number_toilets | female_toilets  |broken_toilets
  ---------------------|-----------------|-------------------
             5         |        2        |       1
  </code></pre>
  
  <p>new rows:</p>
  
  <pre><code>total_number_toilets | female_toilets  |broken_toilets
  ---------------------|-----------------|-------------------
             1         |        'yes'    |      'no'
             1         |        'no'     |      'yes'
             1         |        'yes'    |       'no'
             1         |        'no'     |       'no'
             1         |        'no'     |       'no'
  </code></pre>