Hi all,
I have a process model that calls an expression rule to generate a 6-character random alphanumeric string. I encountered a case where two instances of the process model were triggered at the same time (based on time logs), and both received the same generated value from the expression rule.
I understand that there's always a chance for it to generate the same value. However, I’d like to ask:
Is it possible that both process models used the same instance or execution thread of the expression rule, which might explain why the same value was returned?
Discussion posts and replies are publicly visible
No, Expression rules don't share execution threads. Each process instance gets its own separate execution.Your random generator likely uses system time as a seed. When two processes run at the exact same millisecond, they get the same seed -> same random value.
6 characters isn't that much randomness. So, yes, this can happen.
What do you do with this value?
Thank you for answering. Is there a way to check this?
Try this code once.
mid( substitute( substitute( text(now(), "yyyyMMddHHmmssSSS"), ":", "" ), " ", "" ), 12, 6 )
We’re using it as an identifier. Unfortunately, we can't add more characters due to an external system limitation.
OK, but then you can't just use a random value. You will get duplicates over time.
Did you consider to just use the primary key of a record as the identifier? This would guarantee uniqueness. And you can convert that number into an alphanumeric string if needed.
Any process instance’s id is unique always! If you want random yet unique string then consider using the process id -pp!id- along with whatever code you have for the random string!