function rand(max) { var val = Math.floor(Math.random() * (max + 1)); if(val in rand.tmp) return rand(max); rand.tmp[val] = true; return val; } rand.tmp = {}; alert( rand(100) ); alert( rand(100) ); alert( rand(100) ); alert( rand(100) ); alert( rand(100) );