A Python implementation the Randflake ID: a distributed, uniform, unpredictable, unique random ID generator.
Project description
Randflake ID
Overview
Randflake ID is a distributed, uniform, unpredictable, and unique random ID generator designed to provide robust identifier generation across multiple programming languages and environments.
Key Features
- 🌐 Multi-Language Support: Available in Go, Python, and TypeScript/JavaScript
- 🔒 Cryptographically Secure: Generates unpredictable and unique identifiers
- 🚀 High-Performance ID Generation: Optimized for lock-free operation to minimize latency and maximize throughput
- 📈 Scalable: Engineered to handle high-throughput systems with a maximum ID generation rate of 17,179,869,184 ID/s
- 🔀 Distributed-Friendly: Suitable for distributed systems and microservices
- 📊 Uniform Distribution: Ensures even spread of generated IDs
Installation
Go
go get -u gosuda.org/randflake
Python
pip install randflake
TypeScript/JavaScript
npm install randflake
Usage Examples
Go
package main
import (
"fmt"
"time"
"gosuda.org/randflake"
)
func main() {
now := time.Now().Unix()
nodeid := int64(42)
lease_start := int64(now)
lease_end := int64(now + 600)
secret := []byte("super-secret-key")
g, err := randflake.NewGenerator(nodeid, lease_start, lease_end, secret)
if err != nil {
panic(err)
}
id, err := g.Generate()
if err != nil {
panic(err)
}
fmt.Println(id)
}
Python
import time
from randflake import Generator
now = int(time.time())
nodeid = 42
lease_start = now
lease_end = now + 600
secret = b'super-secret-key'
g = Generator(nodeid, lease_start, lease_end, secret)
uid = g.generate()
print(uid)
TypeScript/JavaScript
import { Generator } from 'randflake';
const now = Math.floor(Date.now() / 1000);
const nodeid = 42;
const lease_start = now;
const lease_end = now + 600;
const secret = new TextEncoder().encode('super-secret-key');
const generator = new Generator(nodeid, lease_start, lease_end, secret);
const uid = generator.generate();
console.log(uid);
Performance
Randflake ID is designed for high-performance scenarios, with minimal overhead in ID generation.
String Representation
Randflake ID is encoded as a base32hex string.
base32hexchars = "0123456789abcdefghijklmnopqrstuv"
original = 4594531474933654033
encoded = "3vgoe12ccb8gh"
def decode(s):
return int(s, 32)
def encode(n):
if n < 0:
n += 1 << 64
if n == 0:
return "0"
result = ""
while n > 0:
result = base32hexchars[n&0x1f] + result
n = n // 32
return result
assert original == decode(encode(original))
assert encode(original) == "3vgoe12ccb8gh"
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE for more information.
More Information
For detailed documentation and additional resources, visit: https://gosuda.org/randflake
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file randflake-1.6.2.tar.gz.
File metadata
- Download URL: randflake-1.6.2.tar.gz
- Upload date:
- Size: 51.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
914e09c858989d25a2828ff687f1445889a9487921c2a5badf1f1b3943056d77
|
|
| MD5 |
540ad073796dbd21e3d96c04875c1615
|
|
| BLAKE2b-256 |
a8174bc2af741a0e6422be413a2e23dfce4710e53c31827d56d66528f5ccd4d1
|
Provenance
The following attestation bundles were made for randflake-1.6.2.tar.gz:
Publisher:
python-publish.yml on gosuda/randflake
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
randflake-1.6.2.tar.gz -
Subject digest:
914e09c858989d25a2828ff687f1445889a9487921c2a5badf1f1b3943056d77 - Sigstore transparency entry: 155445260
- Sigstore integration time:
-
Permalink:
gosuda/randflake@2aba9ec75505f177fb4c2824222d8a9912f7228a -
Branch / Tag:
refs/tags/v1.6.2 - Owner: https://github.com/gosuda
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@2aba9ec75505f177fb4c2824222d8a9912f7228a -
Trigger Event:
release
-
Statement type:
File details
Details for the file randflake-1.6.2-py3-none-any.whl.
File metadata
- Download URL: randflake-1.6.2-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d8859dfd379a8ec77b8e95553c66ec69f934a8298d99d968788b44929fee7e2
|
|
| MD5 |
d0a65d04eb35718701b0609e2c0d7eb7
|
|
| BLAKE2b-256 |
49941a509b6b178a0ba153a0d1034b1d97219f377ffb8bdd35368cff12c99710
|
Provenance
The following attestation bundles were made for randflake-1.6.2-py3-none-any.whl:
Publisher:
python-publish.yml on gosuda/randflake
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
randflake-1.6.2-py3-none-any.whl -
Subject digest:
8d8859dfd379a8ec77b8e95553c66ec69f934a8298d99d968788b44929fee7e2 - Sigstore transparency entry: 155445261
- Sigstore integration time:
-
Permalink:
gosuda/randflake@2aba9ec75505f177fb4c2824222d8a9912f7228a -
Branch / Tag:
refs/tags/v1.6.2 - Owner: https://github.com/gosuda
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@2aba9ec75505f177fb4c2824222d8a9912f7228a -
Trigger Event:
release
-
Statement type: