function rand(val,max){ var arr = [], i = 3, pos = Math.floor(Math.random()*(i+1)); while(i--){ var rnd = Math.floor(Math.random()*max); arr.push(rnd >= val ? ++rnd : rnd); } arr.splice(pos,0,val); return arr } alert(rand(3,5))