Skip to content

newObjectId() - uniqueness poblem #106

Closed
@janswist

Description

@janswist
// 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???

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions