Improvements to random Algorithm