can you use a database? I'd approach this by putting the pegs in a database table. then randomly retrieve a peg which is available. when a random reg is retrieved, update the table to say that is it no longer available.
here is some example SQL (MySQL) code that I used to for something else: "SELECT fieldname FROM tablename WHERE category='$category' AND hide='N' ORDER BY rand() limit 0,10 "