The RandomHash action in the Community Commons module in the Marketplace can generate a UUID.
https://docs.mendix.com/appstore/modules/community-commons-function-library/#39-stringutils
You can also add an After Create action to call this and set an attribute when you create your object.
https://docs.mendix.com/refguide/event-handlers/
I hope this helps.
HI Syrine
If you want UID to be unique and not generated every time you read the object, you need to not create calculated attribute.
UID should be stored.
And then in Before Create/After Create event microflow you can generate unique code and assign it to UID.
This way Microflow will be called once and UID will not be regenerated.