Created
April 1, 2014 00:08
-
-
Save metude/9905109 to your computer and use it in GitHub Desktop.
Rastgele TC Kimlik No Javascript
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 num = Math.floor((Math.random()*999999999)+100000000); | |
console.log("random number: " + num); | |
var str = num.toString(); | |
var num_array = str.split(""); | |
console.log("number array: " + num_array); | |
function interesting_rule(num_array) { | |
var sum_even = parseInt(num_array[1]) + parseInt(num_array[3]) + parseInt(num_array[5]) +parseInt(num_array[7]); | |
var sum_odd = parseInt(num_array[0]) + parseInt(num_array[2]) + parseInt(num_array[4]) +parseInt(num_array[6]) + parseInt(num_array[8]); | |
return ((sum_odd*7)-sum_odd)%10; | |
} | |
console.log("intersting rule result: " + interesting_rule(num_array)) | |
num_array[9] = interesting_rule(num_array).toString(); | |
function sum_digits(number) { | |
var sum = 0; | |
for (var i = 0; i < str.length; i++) { | |
sum += parseInt(str.charAt(i), 10); | |
} | |
return sum%10; | |
} | |
num_array[10] = sum_digits(str).toString(); | |
console.log(num_array.join("")); | |
document.write(num_array.join("")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bir ara revize edeceğim.