stopValue = (int) (Math.random() * 20 + 1); while (counter <= stopValue) { g.drawString("counter is " + counter, 20, counter * 10 + 20); counter = counter + 1; }