Hey Azrealvect!
I was also looking for this for some makeshift trader system. I tried learning Pearl for this but I already had some experience in SQL(Very little really). I ended up with the following that I pretty much looped over and over for the number of MerchantsIds I had in another table.
The script below only shows how to get random items of a certain item type in MariaDB/MySQL. You could easily change this to work to pull any item by removing the "itemtype =" line.
Code:
-- Select used to provide random items to Bazaar merchants
-- All info for fields can be found at https://github.com/EQEmu/Server/wiki and searching for the pages.
-- for classes 15906 = All Casters Classses where 49629 = All Melee Classes and 65535 = All player classes in game.
Select * from peq.items
where itemtype = 0 -- Limit results to specific item types
and reclevel = 0 -- limit results to items with no recommended level
and reqlevel = 0 -- Limit results to items with no required level
and nodrop = 0 -- Removes No drop items from results
and augtype = 0 -- Removes augemnts from results
and damage <= 10 -- Limit results to have a max dmg of 10 or stated number
and damage >= 1 -- Limit results to have weapons with at least the stated dmg.
And classes <= 65535 -- This is the ## for all classes
and classes >= 1 -- This is the ## for warrior
and size > 1 -- This will return items Small to Gigantic
and fvnodrop = 0 -- Return only non No Trade Items
And ac > 0 -- for armor. Limit the bottom end of ac an item can have
and ac < 10 -- for armor. Limit the top end of ac an item can have
and slot = 2048 -- Limit search to a specific slot. 2048 = Range Slot.
ORDER By RAND() -- Will make sure you get a more random set of items
Limit 20; -- Limit the amount of results you get