Unique group name

I am trying to understand (find) the account Username generation algorithm. Is the uniqueness guaranteed by an algorithm or by looking at existing values and making sure it is unique ?

Looked at the nakama codebase, but what i found related to the Username generation doesn’t seem to be the one that ends up in the database (eg. “Player60627429”)

I want to use the same mechanism to generate unique Group names.

Any pointers ?

The player username generation function is in source code:

nakama/server/api_authenticate.go at master · heroiclabs/nakama · GitHub

In Hiro game framework we override the default behaviour to create player usernames which look like the format you’ve shared. i.e. “Player60627429”
We do this with some very simple code:

var (
	defaultUsernameOverrideMutex  = &sync.Mutex{}
	defaultUsernameOverrideRandom = rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
)

var defaultUsernameOverrideFn hiro.UsernameOverrideFn = func() string {
	defaultUsernameOverrideMutex.Lock()
	number := defaultUsernameOverrideRandom.Intn(100_000_000)
	defaultUsernameOverrideMutex.Unlock()
	return fmt.Sprintf("Player%08d", number)
}

The random source needs a short lived mutex lock because its not thread-safe.

Hope that helps.

Thanks. that’s what i needed.