How can I ensure everyone has a unique name?

Hello. I am creating a game where everyone is assigned an N-Number (The number on the side of planes, say N15XF or N69249). Using the basic rules by the FAA (there are some very complex ones), there are 100,000 N-Numbers which are 5 numbers, 240,000 N-Numbers which are 4 numbers 1 letter, and 5,760,000 3 numbers 2 letters. This gives us a total of 6,100,000 N-Numbers. While I know it’s not smart to give myself a limitation of 6,100,000 players to play my game, there are workarounds.

Anyway, assuming I had infinite N-Numbers, my main question is how could I ensure that every player who joined had a unique N-Number?

1 Like

Theres lots of ways to do this as well as everything else. If you wanna make sure everyone has a different number then my main suggestion would be to check out the messaging service and combine it with maybe an ordered data store. With the messaging service you can send out a check to see everyones value and then assign something different.

1 Like

Your simplest solution would simply be to have a global store which you can validate if a key is in use or not (so the user creates their own). Another method would be a system where you can grab the next available ID from the global data store - but you’ll need to add a debounce to make sure that no two people can access it at the same time. Or you do a system which validates afterwards because their is an interesting problem in Computer Science which addresses this system - but more so between when data displaying may not correlate to the datastore in the future.

I feel like calling a datastore that could have millions of values in it is inefficient though.
I want players to have a permanent name. Not one assigned on join.

Thats why I said combine it with an ordered data store > so you could save it

Then the issue loops back around to have a datastore with millions of values in it.

Then just use a regular data store? It wont have a ton of values. Simple fix

Efficiency only really comes into play when their is other suitable methods, you will always have to check some form of global data store to see what numbers are available. If a user chooses the number themselves then this will be inefficient, but a simple grab and increment system is relatively low server calculation usage.

1 Like

How is that relatively low? If it had to iterate through 6,000,000 values, that could easily time out.

1 Like

It depends how you look at it and what system you choose, if you want users to make their own then you’ll have to do some iteration. To a server box, 6 million values is literally nothing when you give it 3-5 seconds - this is covered under time complexity theory (whereby the theory basically says in basics as more data is added, you can expect it to get longer - period). The only way you can guarantee that no one has the same number is through verifying in datastores.

The grab and increment method as I suggested, doesn’t do iteration. You’d simply debounce on, get the current value as your value, increment the datastore by one and then debounce off. Which is a relatively fast process.

Your other alternatives will be mathematical equations which will lower the chance of two people having the same number dramatically at the cost of taking the risk that they might. But then at that point you then have to ask:

  • probability those two people meet.
  • probability two people will catch on at the same second (if your using one which encompasses time itself).

I might just ignore this problem altogether. The issue of having to check a massive datastore database and generate a new unique name is far too complex for the gain I get from doing it. You are right, the likelihood of two players having the same name is one in 6.1 million, or 0.0000163934426%. I can’t assume it’ll be an issue. My bad.

1 Like

I mean another way to do could be you take the letters of their username and transfer it to the correct numbers. Cuz no 2 usernames the same.
Exp -
If my name was abc then my username would be 123. You wouldnt need all those server checks you’re worried about.

That’d be in the vein of developing a hashing algorithm. I am NOT developing a hashing algorithm for this.

1 Like

Well I don’t think you can really afford to be picky with this. You said you want everyone to have a unique number > theres no simple solutions for this.

What about taking first or first two letters of name and combining it with 4 digits from id for example. Chance of having duplicate of that is very low.

Edit: I had some time so here is example of what I think

local Generate = function(Player)
	local Output = ""
	local Letters = string.upper(string.sub(Player.Name,1,1))
	local Id = tostring(Player.UserId)
	if #Id < 4 then
		local Dif = 4 - #Id
		for i = 1,Dif do
			Id = Id.."1"
	local Four = string.sub(Id,1,4)
	Output = Output..Letters..Four
	return Output


The NAA would disagree with this.