Nanoid 3.1.0

dotnet add package Nanoid --version 3.1.0                
NuGet\Install-Package Nanoid -Version 3.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Nanoid" Version="3.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Nanoid --version 3.1.0                
#r "nuget: Nanoid, 3.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Nanoid as a Cake Addin
#addin nuget:?package=Nanoid&version=3.1.0

// Install Nanoid as a Cake Tool
#tool nuget:?package=Nanoid&version=3.1.0                

nanoid-net

Build Status Build status NuGet Badge License

This package is .NET implementation of ai's nanoid!

Safe. It uses thread safe cryptographically strong random generator by default.

Compact. It uses more symbols than UUID (A-Za-z0-9_-) and has the same number of unique options in just 22 symbols instead of 36.

Fast. Nanoid is as fast as UUID but can be used in URLs.

Install

Install with nuget:

PM> Install-Package Nanoid

Usage

Normal

The default method uses URL-friendly symbols (A-Za-z0-9_-) and returns an ID with 21 characters (to have a collision probability similar to UUID v4).

var id = Nanoid.Generate(); //=> "Uakgb_J5m9g-0JDMbcJqLJ"

Symbols -,.() are not encoded in the URL. If used at the end of a link they could be identified as a punctuation symbol.

If you want to reduce ID length (and increase collisions probability), you can pass the size as an argument:

var id = Nanoid.Generate(size: 10); //=> "IRFa-VaY2b"

Custom Alphabet or Length

If you want to change the ID's alphabet or length you can pass alphabet and size.

var id1 = Nanoid.Generate(Nanoid.Alphabets.LowercaseLettersAndDigits, 10); //=> "4f90d13a42"
var id2 = Nanoid.Generate("1234567890abcdef", 5); //=> "2x501"

You can find a variety of useful alphabets typically used for Nanoid generation in Nanoid.Alphabets.

To reason about the collision probabilities of a particular alphabet and id length combination, use the nanoid collision calculator.

Random Bytes Generator and Thread Safety

By default, we use an internal global ThreadStatic wrapper over System.Security.Cryptography.RandomNumberGenerator to generate Nanoids in a cryptographically secure manner.

The ThreadStatic attribute ensures that you can safely generate ids across threads without having to pass in your own Random object, by creating a separate instance of our random number generator per thread. This method also avoids the need for any locks which ensures the id generation is fast as advertised.

You can replace the default safe random generator using the System.Random class. For instance, to use a seed-based generator you can do this:

var random = Random(10);
var id = Nanoid.Generate(random, Nanoid.Alphabets.Letters, 10) //=> "fbAeFaaDeb"

If you want to use your own global random number generator, make sure you are aware of the thread safety implications.

Also note that the global random number generator is lazily initialized on first usage. If you need to preload it you can call the Nanoid.GlobalRandom getter to force the initialization to happen at that moment on the current thread.

Credits

License

The MIT License (MIT). Please see License File for more information.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 is compatible.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.8

    • No dependencies.
  • .NETStandard 2.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages (22)

Showing the top 5 NuGet packages that depend on Nanoid:

Package Downloads
BotSharp.Core

Open source LLM application framework to build scalable, flexible and robust AI system.

Lingman.Utils

Api Log的exception记录

Util.IdGenerator

Util.IdGenerator是Util应用框架的Id生成器封装类库

Meow.Core

Meow.Core 是 Meow 基础类库。 个人学习使用。 来源 作者:何镇汐 地址:https://github.com/dotnetcore/Util 请使用原作者版本,尊重原作者劳动成果,谢谢!

Newguys.Utils

Package Description

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on Nanoid:

Repository Stars
dotnetcore/Util
Util是一个.Net平台下的应用框架,旨在提升中小团队的开发能力,由工具类、分层架构基类、Ui组件,配套代码生成模板,权限等组成。
SciSharp/BotSharp
AI Multi-Agent Framework in .NET
legend2ks/YoutubeDownloader
YouTube video/playlist/channel downloader
Version Downloads Last updated
3.1.0 297,321 6/22/2024
3.0.0 1,102,206 7/29/2023
2.1.0 2,397,001 1/21/2020
2.0.0 60,590 11/16/2018
1.0.0 11,818 12/24/2017

3.1.0
     - Various improvements and fixes. by @SasLuca, @Petteroe
     - Target .NET Framework 4.8 and .NET 8.netstandard2.x no longer being available. by @oddeirik