XML w/ Random Image Function?

I have this XML picture gallery code (props. to Gonzalas) that I would like to modify. I would like for it to randomly load a picture when the .swf loads, and/or by clicking a button. I’m guessing I can do away with the previousImage and nextImage functions, and that I need to create a new function, right? Something like randomImage? Or should I modify the loadImage function? I think I’m on the right path, but lack the skills to tackle this with any sort of confidence.

Can anyone help?

///////////////////////////
function loadPic(pic) {
	picture.gotoAndStop(1);
	picture.fader.contents.loadMovie(pic);
	var temp = _root.createEmptyMovieClip("tmp", 999+d);
	temp.onEnterFrame = function() {
		var t = picture.fader.contents.getBytesTotal(), l = picture.fader.contents.getBytesLoaded();
		preloader._visible = true;
		preloader.preload_bar._xscale = 100*l/t;
		if (l == t && picture._width>0 && picture._height>0) {
			preloader._visible = false;
			var w = picture._width+spacing, h = picture._height+spacing;
			border.resizeMe(w, h);
			delete this.onEnterFrame;
		}
	};
}
MovieClip.prototype.resizeMe = function(w, h) {
	this.onEnterFrame = function() {
		this._width += (w-this._width);
		if (Math.abs(this._width-w)<1) {
			this._height += (h-this._height);
		}
		if (Math.abs(this._width-w)<1 && Math.abs(this._height-h)<1) {
			this._width = w;
			this._height = h;
			picture._x = this._x-this._width/2+spacing/2;
			picture._y = this._y-this._height/2+spacing/2;
			picture.play();
			if (picture._currentframe == 1) {
				picture._alpha = 100;
				delete this.onEnterFrame;
			}
		}
	};
};
function loadXML(loaded) {
	if (loaded) {
		xmlNode = this.firstChild;
		image = [];
		total = xmlNode.childNodes.length;
		for (i=0; i<total; i++) {
			image* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
		}
		firstImage();
	}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("backgrounds.xml");
//////////////////////////////////////
p = 0;
function firstImage() {
	loadPic(image[0]);
	picture.gotoAndStop(1);
}
function nextImage() {
	this.onEnterFrame = function() {
		if (p<(total-1)) {
			picture.prevFrame();
		}
		if (picture._currentframe == 1) {
			picture._alpha = 0;
			p++;
			loadPic(image[p], 1);
			picture.gotoAndStop(1);
			delete this.onEnterFrame;
		}
	};
}
function prevImage() {
	this.onEnterFrame = function() {
		if (p>0) {
			picture.prevFrame();
		}
		if (picture._currentframe == 1) {
			picture._alpha = 0;
			p--;
			loadPic(image[p], 1);
			picture.gotoAndStop(1);
			delete this.onEnterFrame;
		}
	};
}
////////////////////////
spacing = 0;
picture._alpha = 0;
///////////////////////
previous_btn.onRelease = function() {
	prevImage();
};
next_btn.onRelease = function() {
	nextImage();
};
//////////////////////