Skip to content
Advertisement

Generate random 6 characters based on input

Generate random 6 characters based on input. Like I want to turn 1028797107357892628 into j4w8p. Or 102879708974181177 into lg36k but I want it to be consistant. Like whenever I feed 1028797107357892628 in, it should always spit out j4w8p. Is this possible? (Without a database if possible.) I know how to generate random 6 characters but I dont know how to connect it with an input tbh. I would appreciate any help, thanks.

let rid = (Math.random() + 1).toString(36).substring(7); 

Advertisement

Answer

Thanks everyone, solved my issue.

Code:

  let seed = Number(1028797089741811773)
  let rid = seed.toString(36).substring(0,6)
  console.log(rid)

Or:

  let seed = Number(1028797089741811773)
  let rid = seed.toString(36).substring(6)
  console.log(rid)
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement