Created
May 6, 2015 18:08
-
-
Save jaime-ez/0bf905af3ef97fd5cd4e to your computer and use it in GitHub Desktop.
Generate chilean RUT between min and max values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dv, rut, min, max; | |
var M=0,S=1; | |
var T = Math.floor(Math.random() * (max - min + 1)) + min; | |
rut = T; | |
for(;T;T=Math.floor(T/10)) { | |
S=(S+T%10*(9-M++%6))%11; | |
} | |
dv= S?S-1:'K'; | |
rut = rut + '-' + dv; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment