Skip to content

Instantly share code, notes, and snippets.

@THuRStoN
Created March 10, 2014 16:23
Show Gist options
  • Select an option

  • Save THuRStoN/9468324 to your computer and use it in GitHub Desktop.

Select an option

Save THuRStoN/9468324 to your computer and use it in GitHub Desktop.
A random DNI generator for testing purposes in JavaScript
function formatNumberLength(num, length) {
var r = "" + num;
while ( r.length < length ) {
r = "0" + r;
}
return r;
}
function charDNI(dni) {
var chain = "TRWAGMYFPDXBNJZSQVHLCKET";
var pos = dni % 23;
var letter = chain.substring( pos, pos + 1 );
return letter;
}
function rand_dni() {
num = Math.floor( ( Math.random() * 100000000 ) );
sNum = formatNumberLength( num, 8 );
return sNum + charDNI( sNum );
}
@arcovoltaico

Copy link
Copy Markdown

Thanks mate!

@vitoo

vitoo commented Aug 17, 2017

Copy link
Copy Markdown

Thanks :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment