.NET Short Unique Identifier

前端 未结 23 1098
忘掉有多难
忘掉有多难 2020-12-07 11:27

I need a unique identifier in .NET (cannot use GUID as it is too long for this case).

Do people think that the algorithm used here is a good candidate or do you have

23条回答
  •  太阳男子
    2020-12-07 12:10

    Simple usable package. I use it for temporal request id generator.

    https://www.nuget.org/packages/shortid

    https://github.com/bolorundurowb/shortid

    Uses System.Random

    string id = ShortId.Generate();
    // id = KXTR_VzGVUoOY
    

    (from the github page)

    If you want to control the type of id generated by specifying whether you want numbers, special characters and the length, call the Generate method and pass three parameters, the first a boolean stating whether you want numbers, the second a boolean stating whether you want special characters, the last a number indicating your length preference.

    string id = ShortId.Generate(true, false, 12);
    // id = VvoCDPazES_w
    

提交回复
热议问题