Fixed generation of unique id values

Fixes #6371.