Rom name generation

Options
Hi,
I want to get a custom naming system which will have two characteristics:
  1. Length of room name is 4 characters
  2. It has only Upper or lower case characters
I thought to do it by specifying a function which from an set of values (not declared anywhere) takes timestamp as argument and select a unique name. This looks a bit complex.
Second idea was to have a server that issue name, but Ido not like this.

I do not know if photon has any builtin mechanism for customizing room name, so please if there is any let me know.

Comments

  • Eduard
    Options
    Any help on this please?
  • OneManArmy
    OneManArmy ✭✭✭
    edited December 2017
    Options
    why only 4 chars?
  • Eduard
    Options
    because the players can read the code and enter. I can extend this, but first I need an approach how to solve it.
  • Hi @Eduard,

    I guess the name should be randomly generated, shouldn't it? If so you can use Unity's Random functionality in order to create a 'random' number between 65 and 90 (uppercase characters) or 97 and 122 (lowercase characters), take a look at the ASCII table for more information. Then you can cast this number to a char and furthermore append this char to a string. In code this might look like the following:
    public void CreateRandomName()
    {
        string name = "";
    
        for (int counter = 1; counter <= 4; ++counter)
        {
            bool upperCase = (Random.Range(0, 2) == 1);
    
            int rand = 0;
            if (upperCase)
            {
                rand = Random.Range(65, 91);
            }
            else
            {
                rand = Random.Range(97, 123);
            }
    
            name += (char)rand;
        }
    
        Debug.Log(name);
    }
  • Eduard
    Options
    Hi @Christian_Simon.
    Yes name should be randomly generated. But if we generate it in unity we need to compare it again all other room names. At as the number of rooms increases I guess that the chance that generated string will not be unique, so there are a lot of for loops.
    I hope someone from photon technical support will comment here to see this approach:
    Like Christian said we generate string then we try to create room. if oncreateroomfailed is called then we repeat again. What are drawbacks of this?
  • [Deleted User]
    edited December 2017
    Options
    When using this approach you have 52^4 different possibilities for the name which is a lot. So I guess it will take some time until you really got an already existing name. If this happens anyway you already have OnCreateRoomFailed callback to re-run the procedure and as far as I would say there is no problem with running this procedure even up to five times which is an absolutely worst case scenario.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    @Eduard FYI:
    I hope someone from photon technical support will comment here to see this approach

    my colleague @Christian_Simon is the best "someone from photon technical support".
  • Eduard
    Options
    ok thank you both for your help.