sonyflake | A distributed unique ID generator inspired by Twitter | Theme library

 by   sony Go Version: v1.1.0 License: MIT

kandi X-RAY | sonyflake Summary

kandi X-RAY | sonyflake Summary

sonyflake is a Go library typically used in User Interface, Theme applications. sonyflake has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

[Go Report Card] Sonyflake is a distributed unique ID generator inspired by [Twitter’s Snowflake] Sonyflake focuses on lifetime and performance on many host/core environment. So it has a different bit assignment from Snowflake. A Sonyflake ID is composed of.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              sonyflake has a medium active ecosystem.
              It has 3170 star(s) with 274 fork(s). There are 53 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 3 open issues and 17 have been closed. On average issues are closed in 137 days. There are 4 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of sonyflake is v1.1.0

            kandi-Quality Quality

              sonyflake has 0 bugs and 0 code smells.

            kandi-Security Security

              sonyflake has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              sonyflake code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              sonyflake is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              sonyflake releases are not available. You will need to build from source code and install.
              Installation instructions are not available. Examples and code snippets are available.
              It has 364 lines of code, 25 functions and 4 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of sonyflake
            Get all kandi verified functions for this library.

            sonyflake Key Features

            No Key Features are available at this moment for sonyflake.

            sonyflake Examples and Code Snippets

            No Code Snippets are available at this moment for sonyflake.

            Community Discussions

            QUESTION

            12 digit unique distributed random number generator
            Asked 2020-Apr-23 at 10:42

            I ported sonyflake to Java and it worked fine. However, instead of generating 8 digit numbers, I am looking to generate 12 digit unique numbers. The original port uses 16-bit machineId. Because we have at least 2 data centers, but not limited to, I added 8-bits for the data center - using the second octet of the IP address. I tweaked all the settings for the bit lengths, couldn't manage to generate 12-digits numbers. Is there an algorithm inspired by sonyflake or Twitters Snowflake to generate unique 12-digit numbers which uses 16-bit machineId and 8-bit dataCenterId?

            Note: Due to company policy, I cannot post my original Java port here.

            EDIT: This is what I came up with. However, instead of generating 12 digit decimal numbers, it generates 10 or 11 digit numbers. What changes can I make to for it to always return a 12-digit decimal number? I understand I need to change the sequence and recalculate the time. However, I currently want to focus on generating a 12-digit decimal number.

            ...

            ANSWER

            Answered 2020-Apr-23 at 10:42

            If you mean 12 decimal digits, then you can use a number up to 39 bits (40 bits can represent 13-digit in addition to 12-digit numbers).

            If you take 16 bits for the machine ID, and 8 bits for the data center ID, that leaves only 15 bits for the unique portion of the ID for that machine (so only 32768 unique numbers per machine.) With so few numbers, you can choose to assign the numbers sequentially rather than randomly.

            If you mean 12 hexadecimal (base-16) digits, then the situation improves considerably: 16 bits makes up 4 digits and 8 bits makes up another two, leaving 6 base-16 digits for the unique portion of the ID, or 16,777,216 different numbers (24 bits). With this many numbers, you have several different choices to have each machine assign these numbers. You can do so sequentially, or at random (using java.security.SecureRandom, not java.util.Random), or using a timestamp with 10 ms resolution, as in Sonyflake.

            It appears your question is less about how to generate a 12-digit unique ID than it is about how to format a number to fit in exactly 12 digits. Then you have two options. Assume you have a 39-bit integer x (less than 239 and so less than 1012).

            • If you can accept leading zeros in the number, then do the following to format x to a 12-digit number:String.format("%012d", x).

            • If you can't accept leading zeros in the number, then add 100000000000 (1011) to x. Since x is less than 239, which is less than 900000000000, this will result in a 12-digit number.

            You are generating worker IDs at random. In general, random numbers are not enough by themselves to ensure uniqueness. You need some way to check each worker ID you generate for uniqueness. Once you do so, each worker/datacenter pair will be unique. Thus, each machine is required only to generate a machine-unique number, which will be 25 bits long in your case. There are several ways to do so:

            • The simplest way is to generate a random number or time-based number (using all 25 bits in your example) and check the number for uniqueness using a hash set (e.g., java.util.HashSet). If the number was already generated, try again with a new number. (Instead of a hash table, it may be more memory-efficient to use a bit set (e.g., java.util.BitSet) or a compressed bitmap (e.g., a "roaring bitmap").)

            • Another way is to use a hash table with random/time-based numbers as keys and sequence IDs as values. When a unique number needs to be generated, do the following:

              1. Generate X, a random number or time-based number.
              2. Check whether a key equal to X is found in the hash table.
              3. If the key does not exist, create a new entry in the table, where the key is X and the value is 0. The unique number is X and a sequence number of 0. Stop.
              4. If the key exists, and the value associated with that key is less than 255, add 1 to the value. The unique number is X and a sequence number of that value. Stop.
              5. If the key exists, and the value associated with that key is 255 or greater, go to step 1.

            Source https://stackoverflow.com/questions/61367508

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install sonyflake

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/sony/sonyflake.git

          • CLI

            gh repo clone sony/sonyflake

          • sshUrl

            git@github.com:sony/sonyflake.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Explore Related Topics

            Consider Popular Theme Libraries

            bootstrap

            by twbs

            tailwindcss

            by tailwindlabs

            Semantic-UI

            by Semantic-Org

            bulma

            by jgthms

            materialize

            by Dogfalo

            Try Top Libraries by sony

            nnabla

            by sonyPython

            gobreaker

            by sonyGo

            v8eval

            by sonyC++

            ai-research-code

            by sonyPython