Basil_JS, или random(0,39,40)
<script language="JavaScript" type="text/javascript">
function random(min,max,l)
{var arr = [],m = [],n = 0;
if (max - min < l-1) return;
for (var i=0; i<=(max-min); i++)m[i] = i + min;
for (var i=0; i<l; i++) {n = Math.floor(Math.random()*(m.length)); arr[i]=m.splice(n,1)[0];};
return arr
}
document.write(JSON.stringify(random(1,40,40)))
</script>