(1) for to do
(2)  // memory consideration
(3)  if then
(4)   Choose a harmony from HM randomly,
(5)   
    // pitch adjustment
(6)   if then
(7)    Generate a random integer number
     // represents the index of the best harmony in the HM
(8)    
(9)   end if
(10)  else
(11)   // random selection
(12)  end if
(13) end for
Algorithm 2: The procedure of improvising a new harmony of GHS.