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

newObjectId() - uniqueness poblem #106

Closed
janswist opened this issue Jan 31, 2016 · 1 comment
Closed

newObjectId() - uniqueness poblem #106

janswist opened this issue Jan 31, 2016 · 1 comment

Comments

@janswist
Copy link

// Returns a string that's usable as an object id.
// Probably unique. Good enough? Probably!
function newObjectId() {
  var chars = ('ABCDEFGHIJKLMNOPQRSTUVWXYZ' +
               'abcdefghijklmnopqrstuvwxyz' +
               '0123456789');
  var objectId = '';
  for (var i = 0; i < 10; ++i) {
    objectId += chars[Math.floor(Math.random() * chars.length)];
  }
  return objectId;
}

How are we supposed to use that without certainity that it will always create unique objectId???

@gfosco
Copy link
Contributor

gfosco commented Feb 1, 2016

There's a PR to enhance the entropy using better random bytes, which we'll likely accept, but honestly this is not that bad (something like 1 in 900 million). Will be resolved with #73.

@gfosco gfosco closed this as completed Feb 1, 2016
BernhardHarrer pushed a commit to BernhardHarrer/parse-server that referenced this issue Feb 22, 2017
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

2 participants