Random item link, multiple loops

Hi,

I'm trying to generate a simple link to a random item in the archive, which I'll put in the site header.

The code below has two problems. One is that it's not a very efficient way to get a random item id. But more importantly, it interferes with the main item loop on the page (so on items/browse for example, it ends up shuffling the item results; on items/show, it randomizes the item being displayed on the page).

function random_item_link(){
	$random=recent_items(total_items());
	shuffle($random);
	set_items_for_loop($random);
	if (has_items_for_loop()){
		$index=1;
		while ( (loop_items()) && ($index==1) ){
			$id=item('id');
			return '<a id="random-item-link" href="'.WEB_ROOT.'/items/show/'.$id.'">Show me a random item</a>';
			$index++;
		}
	}
}

So I guess the main question is what I need to do to have multiple loops on the same page?

Thanks - E

You're just looking to get one random item? You don't need to do any looping at all:

function random_item_link()
{
    $items = get_items(array('random' => 1), 1);
    $item = $items[0];
    return link_to($item, 'show', 'Show me a random item', array('id' => 'random-item-link'));
}

Oh right. Thanks!