Here are Phil's first changes.  I have added a random number genrator.