For spawning creatures, you can use
https://docs.larian.game/Osiris/API/CharacterCreateAtTrigger or the other calls linked from that page.
Treasure tables are, indeed, random, selecting from a pre-defined set of items or categories of items. They have a considerable amount of functionality to keep the results balanced on both the small and the large scale.
How they work is documented here:
https://docs.larian.game/Treasure_TablesThere's no scripting involved in setting up a treasure table for an container. However, as far as I know there's no built-in functionality that allows you to spawn something from a treasure table at a trigger.
If you want to use a treasure table, the best you can do is probably to use a dummy container and the GenerateTreasure call, then move the contents of that container to the trigger.
Be advised, though, that spawning a very large number of creatures will be a strain on performance. For this case, it's better to use
https://docs.larian.game/Osiris/API/TemporaryCharacterCreateAtTrigger instead.