 <p>More elegant with shorter and more readable using <code>java.util.Random</code> and <code>IntStream</code></p> <pre><code>Random random = new Random(); random.ints(10, 0, 10000).boxed().forEach(randomIntegers::add); </code></pre>