![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
SCRU128 ID is yet another attempt to supersede UUID in the use cases that need decentralized, globally unique time-ordered identifiers. SCRU128 is inspired by ULID and KSUID and has the following features:
import { scru128 } from "scru128";
console.log(scru128()); // e.g. "00PGHAJ3Q9VAJ7IU6PQBHBUAK4"
console.log(scru128()); // e.g. "00PGHAJ3Q9VAJ7KU6PQ92NVBTV"
A SCRU128 ID is a 128-bit unsigned integer consisting of four terms:
timestamp * 2^84 + counter * 2^56 + per_sec_random * 2^32 + per_gen_random
Where:
timestamp
is a 44-bit unix time in milliseconds biased by 50 years (i.e.
milliseconds elapsed since 2020-01-01 00:00:00+00:00, ignoring leap seconds).counter
is a 28-bit counter incremented by one for each ID generated within
the same timestamp
and reset to a random number every millisecond.per_sec_random
is a 24-bit random number refreshed only once per second.per_gen_random
is a 32-bit random number renewed per generation of a new ID.This is essentially equivalent to allocating four unsigned integer fields to a 128-bit space as follows in a big-endian system, and thus it is easier to be implemented with bitwise operators than arithmetic operators in many languages.
Bit numbers | Field name | Length | Data type |
---|---|---|---|
Msb 0 - 43 | timestamp | 44 bits | Unsigned integer |
Msb 44 - 71 | counter | 28 bits | Unsigned integer |
Msb 72 - 95 | per_sec_random | 24 bits | Unsigned integer |
Msb 96 - 127 | per_gen_random | 32 bits | Unsigned integer |
SCRU128 utilizes monotonic counter
to guarantee the uniqueness of IDs with the
same timestamp
; however, this mechanism does not ensure the uniqueness of IDs
generated by multiple generators that do not share a counter
state. SCRU128
relies on random numbers to avoid such collisions.
For a given length of random bits, the greater the number of random numbers
generated, the higher the probability of collision. Therefore, SCRU128 gives
some random bits a longer life to reduce the number of random number generation
per a unit of time. As a result, even if each of multiple generators generates a
million IDs at the same millisecond, no collision will occur as long as the
random numbers generated only once per second (per_sec_random
) differ.
That being said, the per_sec_random
field is refreshed every second to prevent
potential attackers from using this field as a fingerprint to identify a
generator. Also, the 32-bit per_gen_random
field is reset to a new random
number whenever an ID is generated to make sure the adjacent IDs generated
within the same timestamp
are not predictable.
A SCRU128 ID is encoded to a string as a 128-bit unsigned integer denoted in the
radix of 32 using the digits of [0-9A-V]
, with leading zeros added to form a
26-digit canonical representation. Converters for this simple base 32 notation
are widely available in many languages; even if not, it is easily implemented
with bitwise operations by translating each 5-bit group, from the least
significant group to the most, into one digit of [0-9A-V]
, from the least
significant digit to the most. Since the three most significant bits are mapped
to one of [0-7]
, any numeral greater than 7VVVVVVVVVVVVVVVVVVVVVVVVV
is not
a valid SCRU128 ID.
Note that this is different from the encodings commonly referred to as base32 or base32hex (e.g. RFC 4648), which read and translate 5-bit groups from the most significant one to the least.
Copyright 2021 LiosK
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
FAQs
SCRU128: Sortable, Clock and Random number-based Unique identifier
We found that scru128 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.