I would wadger a solution for what your trying to do could be very similar to the native hotel account setup I did which used a automation command flow to create and update a seccond entity.
Your random coupon number would be the command value of an execute automation command going in to a coupon generation command rule.
Using the command value it would make the coupon entity, and then update entity data actions would update the required entity data again using the command value for the entity name.
There is allot more to the example that you will need but take a look and you might get the insparation to sort yourself before I get home;