Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Max unique time range? #113

Open
zhaoyao91 opened this issue Feb 23, 2018 · 2 comments
Open

Max unique time range? #113

zhaoyao91 opened this issue Feb 23, 2018 · 2 comments

Comments

@zhaoyao91
Copy link

As I understood, given fixed seed, workerId, the generated ids are unique, so the only thing that decides which id to generate is the time. However, the combinations are limited, so the uniqueness could only be ensured within some time range. If I keep generating ids over that time range, I must enter another loop and get duplicated ids.

Is that right? what's the max time range this package guarantee?

@mcchin
Copy link

mcchin commented Mar 9, 2018

Not sure if this answer your concern, but by looking at the codes, seems like you need to do this every year to keep the uniqueness?

// Ignore all milliseconds before a certain time to reduce the size of the date entropy without sacrificing uniqueness.
// This number should be updated every year or so to keep the generated id short.
// To regenerate `new Date() - 0` and bump the version. Always bump the version!
var REDUCE_TIME = 1459707606518;

The codes is from here https://github.com/dylang/shortid/blob/master/lib/build.js

@ai
Copy link
Collaborator

ai commented Jul 8, 2018

Yeap, to using just hardware random generator is much safer way. Use Nano ID.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants