NanoId is 40% faster than UUID and uses a larger alphabet than UUID (A-Za-z0-9_-), so default size is reduced from 36 to 21 symbols. Numbers, English letters and special character (ZeroMQ (Z85) alphabet)ĪPI Uuid.nanoId(len, alphabet, randomFunc ):String Numbers, English letters and special character ![]() Numbers and english alphabet without lookalikes: 1, l, I, 0, O, o, u, v, 5, S, s Returns the RFC 4122 identifier of the X.500 namespace Returns the RFC 4122 identifier of the ISO OID namespace Returns the RFC 4122 identifier of the URL namespace Returns the RFC 4122 identifier of the DNS namespace Get the current Unix time in milliseconds Set custom Epoch time, default is 1420070400 Set unique datecenter id, default is random between 0 and 31 Set unique machine id, default is random between 0 and 31 Test a string to see if it is a valid UUID Return random value between 0 and 255 (included)Ĭonvert short uuid to Uuid based on the alphabetĬonvert Uuid to short uuid based on the alphabetĬonvert any string from one alphabet to another You can use Uuid to get any random number between some range, based on Xorshift128+ RNG, using the following code: var dice:Int = Uuid.randomFromRange(1,6) API SummaryĬreate a tiny, secure, URL-friendly, unique string IDĬreate a version 3 (namespace with MD5) UUIDĬreate a version 5 (namespace with SHA-1) UUID Here is example for custom random function using Std.random public function secureRandom():Int The default random generator is Xorshift128+. Var vOctal = nvert(vBase58, Uuid.FLICKR_BASE58, Uuid.NUMBERS_OCT ) // convert from Base58 to octal format Random generatorįor Uuid.v1() and Uuid.v4() you can pass any random function which return value between 0 and 255. Var vBase58 = nvert(vHex, Uuid.NUMBERS_HEX, Uuid.FLICKR_BASE58) // convert hex to Base58 format Var vHex = nvert(vBinary, Uuid.NUMBERS_BIN, Uuid.NUMBERS_HEX) //convert bunary to hex format var vBinary = nvert("273247893827239437",Uuid.NUMBERS_DEC,Uuid.NUMBERS_BIN) //convert decimal to binary format Use nanoId to search in database.Ĭonvert from any base to another base ( binary, hex, decimal, octal and many others). Var searchUid = Uuid.toNano(uuid) // Server receive uuid and convert to NanoId. Var uuid = omNano(uniqueId) // Convert NanoId to Uuid and show on user screen var uniqueId = Uuid.nanoId() // Generate unique id and store in database Here is an example of usage, where we store nanoId in the database ( it's much more compact), but it is shown to the user as uuid, for readability and security reasons. |-| 42 bit timestamp Convert from/to one type to another It can take up to 4096 unique values in a millisecond.īreakdown of bits for an id e.g. Counter - a 12 bit long counter of a self-increasing sequence.It can take up to 32 unique values (including 0) Machine Id - a 5 bit long machine identifier. ![]() Datacenter Id - a 5 bit long datacenter identifier.Timestamp - a 42 bit long number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.Can use time as first component and remain sortableĮach Flake ID is 64 bits long, consisting of:.Flake IDs are 64-bits, half the size of a UUID.Nano ID was ported to many programming languages.įlakeId is a distributed ID generation algorithm based on Twitter Snowflake. So ID size was reduced from 36 to 21 symbols. It uses a larger alphabet than UUID ( A-Za-z0-9_-). It uses Xorshift128+ RNG and can use any cryptographically strong RNG. nanoidĪ tiny, secure, URL-friendly, unique string ID generator ( based on nanoid ). It also provides translators to convert back and forth from RFC compliant UUIDs to the shorter formats. Generate and translate standard UUIDs into shorter - or just different - formats and back ( based on short-uuid ). Version 3 use Md5 for hash and version 5 use Sha1. Port from node-uuid and using built-in Xorshift128+ for random generator. Support for 1, 3, 4 and 5 versions of UUID. Cross-platform generation of UUID based on RFC-4122.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |