 <p>I'm going to be lazy here and take @H2CO3's answer to be working without trying it.</p> <pre><code>&lt;script type="text/javascript"&gt; function generate(var UNWANTED) { var r; do { r = Math.floor(Math.random() * 10); } while (r == UNWANTED); return r; } function GENERATE_RANDOM_FROM_0_TO_10_BUT_NOT_6_OR_SOMETHING_ELSE_(var NOT_GOOD){ return generate(NOT_GOOD) &lt;== One line solution. } &lt;script&gt; </code></pre>