Can I get in trouble for an unfiltered random string?

In my game, I have a custom private server system. For ease of use, all servers are assigned a random, 5 character code. You can use that code to join servers directly.

Can I get in trouble if the generated code ends up being inappropriate?

Here is my code:

function makeCode()
	local code = ""

	local min, max = ("a"):byte(), ("z"):byte()

	for i = 1, 5 do
		code ..= string.char(math.random(min, max))
	end

	code = string.upper(code)

	return code
end

There are bad words that are 5 characters long, so Im wondering if I should filter this somehow? Dont know if thats a good idea though, since the filter system would probably filter every other code for no reason.

I suggest taking a look at:

when creating the random string you can simply check if it is a bad word, and if so then re-generate it.

the chances of that would be very low 11881376 to however many 5 letter swear works are out there (if I did the math right)

Even if it is rare it can happen and it is good to have protection

1 Like

If you take a look at:

there is an entire section for what you’re looking for.

Has some pretty great resources, and code examples.

2 Likes

true, but it’s random so it’s not really @BackspaceRGB’s fault if there is something inappropriate

That’s not what he is asking. Yes, there is a low chance but it still can happen. It’s good to take the extra steps and precautions to make sure.

Next time when responding to a topic or question make sure your answer is valid and corresponds to the original question.

2 Likes

I’d recommend using six digit numbers instead as they are relatively easy to remember/type, there are one million unique combinations of them and they would not be considered inappropriate.

Added filtering, and there is a lot of harmless codes that get marked as inappropriate:
image

Though its fine since it seems to filter them quite fast

1 Like