Skip to content

[js] 第646天 写一个方法生成不重复的用户ID #3465

Open
@haizhilin2013

Description

@haizhilin2013
Collaborator

第646天 写一个方法生成不重复的用户ID

3+1官网

我也要出题

Activity

xujs0813

xujs0813 commented on Jan 21, 2021

@xujs0813
function getUuid(len){
    let timeStr = String(Date.now() % 100)
    const str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
    for(let i=0;i<len - timeStr.length;i++){
        const idx = Math.floor(Math.random() * str.length) 
        timeStr += str[idx]
    }
    const arr = timeStr.split('')
    arr.sort(()=>Math.random()-.5)
    return arr.join('')
}
jxtprivate

jxtprivate commented on Mar 28, 2023

@jxtprivate
function uuid() {
  const randomPart = Math.random().toString(36).substring(2, 6) + Math.random().toString(36).substring(2, 6);
  const timestampPart = Date.now().toString(36);
  return randomPart + timestampPart;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    jsJavaScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @haizhilin2013@xujs0813@jxtprivate

        Issue actions

          [js] 第646天 写一个方法生成不重复的用户ID · Issue #3465 · haizlin/fe-interview