When you say it works what do you mean exactly because that condition is not good. You'll probably find the item names are wrong and all the first value of the array? Technically the actions are correct though. With that condition you are saying to pick a random array object not a random value inside the array.
To fix this, drop the condition. At the top of the actions set a local variable to the value round(random(0,inventory.width)) to choose a random row of the array. This variable will then be the item you need, you can use the variable in the other actions such as ItemName becomes inventory.at(variable).