Fixed generation of unique id values

Fixes #6371. Fixes wet-boew/GCWeb#872.