CreateItemOnObject("item_template", GetObjectByTag("ChestTag", Random());
This is done before the player starts opening chests. It assumes there are 8 chests with the same tag. Random(
returns an integer in the range 0-7, which is OK here, because GetObjectByTag numbers the instances as 0-7.
To make it more general, you could count the number of chests first, then use the actual number rather than 8.
If you prefer unique tags, you could tag the chests as ChestTag0 - ChestTag7:
CreateItemOnObject("item_template", GetObjectByTag("ChestTag" +IntToString(Random()));