var idArr = [];
for (var i = 0; i < $('ul').length; i++) {
while (true) {
var randomId = Math.floor(Math.random() * 100000);
if (idArr.indexOf(randomId) == -1) {
idArr.push(randomId);
break;
}
}
}
$('elem').each(function(i, elem) {
this.id = idArr.pop();
});