If it's that kind of design then for a start you create several of the same slots for the loot bag and spawn a random item to them which I imagine would be setting a random slot.itemname or creating an object on the slot itself, however you have done it earlier. You can copy all logic from the inventory, then you should be able to move items from those slots to your inventory in the same way that you move items around the inventory.
For the loot you can have all items in an array and pick a random row for example and then create this object or set itemname on the slot, or in a more simple form you can set slot.itemname to choose('sword','armour','potion') for example which picks one at random. Then you expand the logic as you go based on what loot can spawn, if enemy that died=goblin then set loot to choose(A,B,C)).
To run it for each slot you could give the lootbag slots a variable to differentiate them from the inventory ones and say for each slot, where variable=loot, run the spawn item logic.
...but how do I make it to where an item gets selected and then it spawn the corresponding sprite based on what get's selected... and also how would I give it probabilities (For Legendaries and such)
Apologies if I'm sounding dumb, I've just never really used arrays before