Skip to content

Commit

Permalink
refactor: use math random better for uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
notthatjen committed Jun 20, 2024
1 parent c2ab6cf commit b6b2e24
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
8 changes: 1 addition & 7 deletions lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,7 @@ export class Entity {
}

generateEntityUUID() {
return 'Entity' + Date.now() + this.cryptoRandomString()
}

cryptoRandomString() {
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
);
return 'Entity' + Math.floor(performance.now() * 1000).toString(36) + Math.random().toString(36).substr(2, 9);
}

async init() {
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class Observer {
}

generateUUID() {
return 'ScriptID' + Date.now() + this.cryptoRandomString()
return 'ScriptID' + Math.floor(performance.now() * 1000).toString(36) + Math.random().toString(36).substr(2, 9);
}

cryptoRandomString() {
Expand Down

0 comments on commit b6b2e24

Please sign in to comment.