Fix random creation algorithm