def get_next_stochastic(board) nextboard <- new array bestboard <- new array pairlist <- new array, this stores lists of pairs, column numbers that conflict h0, pairlist <- h(board) copy board array into nextboard and bestboard count <- 0 pick a random column in nextboard pick a random row in that column, other than the current row in the column nextboard[col] <- row score this new configuration of nextboard: nexth, pairlist <- h(newboard) if nexth < h0 update h0 as the new low score copy into nextboard into bestboard else reset to the previous row, column value of nextboard nextboard[col] <- previous row value end until h0 == 0 or count > 20000 return h0, nextboard end def main board = [] pairlist = [] generate random board h0, pairlist <- h(board) pairlist is a list of conflicting pairs of column numbers hbest, best = get_next_stochastic(board) end