Hi,
this is a tricky problem. I don't think that MySQL itself has such a function. The problem is that you would have to read out the complete table which is very time cosuming. Which number of records do you expect to be in that table ?
The following solution is the only one I could think of to be some kind of acceptable:
Create to tables, one stores the names with an id
tblName:
nameid,name
1,Cat
2,Dog
3,Mouse
Create a second table containing the id's of the first table:
tblWeight:
weightid,nameid
1,1
2,2
3,2
4,2
5,3
6,3
The first field in the second table (weightid) isn't neccessary at all but it will help you for debugging reasons or if you want to extend your database layout at a later time.
Insert n name id's for each name representing the weight
Then do a select like
SELECT name from tblName,tblWeight WHERE tblName.nameid=tblWeight.nameid;
Then use mysql_fetch_array to fetch all records and select a random row of that array. You will most like get a name with a heigher weight because there are more records with the id of that name in the result set.
This is only useful if you don't expect to have millions of names in your database but it should work with a moderate number of records 🙂