mercredi 19 février 2020

Angular / JS generate random Uniq Serial ID

I'm creating a function that generate a random Uniq Serial id by replacing a string with this format ; xxxx-xxxx-xxxx-xxxx , the goal is to get a serial like that : ABCD-1234-EFGH-5678 ,the first and third parts are a letters and the second and last parts are numbers, this is my code :

public generateUniqSerial() {
   return 'xxxx-xxxx-xxx-xxxx'.replace(/[x]/g, function (c) {
     let r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8)
     return v.toString(16)
   })
 }

it give a result like that : "7f8f-0d9a-fd5-450f" , how to edit this function to get a result with this format : ABCD-1234-EFGH-6789




Aucun commentaire:

Enregistrer un commentaire