# Unique group name

**URL:** <https://forum.heroiclabs.com/t/unique-group-name/5690>\
**Category:** Runtime Framework\
**Tags:** groups\
**Created:** [October 5, 2024, 4:14pm UTC](https://forum.heroiclabs.com/t/unique-group-name/5690 "2024-10-05T16:14:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jell-o-fishi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/jell-o-fishi/32/2269_2.png) [@jell-o-fishi](https://forum.heroiclabs.com/u/jell-o-fishi)\
**Post date:** [October 5, 2024, 4:14pm UTC](https://forum.heroiclabs.com/t/unique-group-name/5690/1 "2024-10-05T16:14:10Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![novabyte](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/novabyte/32/1324_2.png) [@novabyte](https://forum.heroiclabs.com/u/novabyte)\
**Post date:** [October 6, 2024, 12:43pm UTC](https://forum.heroiclabs.com/t/unique-group-name/5690/2 "2024-10-06T12:43:27Z")

</div>

The player username generation function is in source code:

[nakama/server/api\_authenticate.go at master · heroiclabs/nakama · GitHub](https://github.com/heroiclabs/nakama/blob/master/server/api_authenticate.go#L755)

In [Hiro game framework](https://heroiclabs.com/hiro/) 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:

```go
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.

---

<div class="post-metadata">

**Author:** ![jell-o-fishi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/jell-o-fishi/32/2269_2.png) [@jell-o-fishi](https://forum.heroiclabs.com/u/jell-o-fishi)\
**Post date:** [October 6, 2024, 1:05pm UTC](https://forum.heroiclabs.com/t/unique-group-name/5690/3 "2024-10-06T13:05:09Z")

</div>

Thanks. that’s what i needed.
