How can I generate a registration number in PloneFormGen?

For more complex use cases like this I tend to use Plomino. It gives you a proper query interface to do things like ensure an id is unique against your saved records.