Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/remeh/goid
Basic package to generate pseudo-random unique IDs.
https://github.com/remeh/goid
Last synced: about 1 month ago
JSON representation
Basic package to generate pseudo-random unique IDs.
- Host: GitHub
- URL: https://github.com/remeh/goid
- Owner: remeh
- Created: 2014-07-07T17:55:13.000Z (over 10 years ago)
- Default Branch: dev
- Last Pushed: 2014-07-14T12:23:14.000Z (over 10 years ago)
- Last Synced: 2024-10-12T22:30:40.213Z (2 months ago)
- Language: Go
- Size: 141 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# goid
Basic package to generate pseudo-random unique IDs.
## Example
By providing the dictionary:
```
dictionary := make([]byte, 4)
dictionary[0] = '0'
dictionary[1] = 'A'
dictionary[2] = '2'
dictionary[3] = 'z'
```You're able to generate as many IDs as you want by providing the number
of already generated keys :```
for i := 0; i < 20; i++ {
fmt.Println(goid.GenerateNext(dictionary, i, 0));
}
```Displays :
```
0
A
2
z
0A
AA
2A
zA
02
A2
22
z2
0z
Az
2z
zz
00A
A0A
20A
z0A
0AA
AAA
2AA
zAA
02A
A2A
```This algorithm is limited to generate `(2^31) - 1` different values (signed int max) due to its design. It's a design choice : it could have been easily extended by using int64 but the performance should have been impacted.
## Roadmap
- Randomized dictionary