Is there any reason why you need this as a script? You do know you can just use eventing to do this, calling a Common Event when the item bag is used.
Set a variable to a random number 1-100, then use a series of conditional branches. Granted, scripting it would probably be faster and easier on the eyes to set up.