Randomized imperative solution (for giggles)