Экпирементируйте
var ch = <?=$i?>,
prev,
rand = function() {
var n = Math.floor(Math.random() * ch) + 1;
return n == prev ? rand() : (prev = n);
};
$('#btn-rnd').click(function() {
var n = rand();
$('#tab-' + n).fadeOut(500, function() {
$(this).load('fun-' + n + '.php').fadeIn(500);
});
});