私はこれのために独自の関数を書くことになりました。そのようなゲットーですが、それは仕事をします。うまくいけば、これは他の誰かに役立つでしょう:P
function generateName(name) {
if(name != null) {
// prepare the variables
var sum = 0;
var total = 0;
var points = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26];
// get the string
var string = name.replace(/[^a-zA-Z]/g, "");
if(string.length > 50) {
string = string.substring(0,50);
}
// tally up the points of the letters
for(var i = 0; i < string.length; i++ ) {
var letter = string.charAt(i).toUpperCase();
var letterIndex = letter.charCodeAt(0) - 65;
sum += points[letterIndex];
}
// make the number bigger
if(sum % 2 === 0) {
if(sum < 100) {
total = parseInt(Math.pow(sum, (sum)));
}
else
{
total = parseInt(Math.pow(sum, (sum / 100)));
}
console.log("it was even" + total);
}
else {
for(var i = 0; i < (sum*sum); i++) {
parseInt(total = total + sum);
}
}
total = total + string.length;
// check if the value is in a valid range, if not, loop again
var word1 = total;
while(word1 > 25000) {
word1 = parseInt(word1 / 2);
}
var word2 = parseInt(word1.toString().split("").reverse().join(""))+string.length;
while(word2 > 25000) {
word2 = parseInt(word2 / 2);
}
}
else {
var word1 = Math.floor((Math.random()*25000)+1);
var word2 = Math.floor((Math.random()*25000)+1);
}
$.ajax({
type: "POST",
url: "names.txt",
}).done(function(msg) {
var names = msg.split('\n');
var name1 = names[word1].toLowerCase().replace(/\b[a-z]/g, function(letter) { return letter.toUpperCase(); });
var name2 = names[word2].toLowerCase().replace(/\b[a-z]/g, function(letter) { return letter.toUpperCase(); });
$("#name-space").hide();
$("#name-space").html("<div id=\"name-wrapper\">Your name is:<br /><h1>" + name1 + " " + name2 + "</h1></div>");
$("#name-space").fadeIn(100);
});
}