var Nmin = 1;
var Nmax = 50;
var N = Math.floor(Math.random()*(Nmax+1 - Nmin)) - Nmin;

var Kmin = 1;
var K = Math.floor(Math.random()*(N+1 - Kmin)) - Kmin;

var arr = ["A","B","C"];
var S = [];
for(i=0;i<N;i++){
    var random = arr[Math.floor(Math.random()*arr.length)];
    S.push(random);
}

var SnoKmojime = S[K];

if(SnoKmojime === "A"){
    var sourceStr = S;
    var targetStr = SnoKmojime;
    var regExp = new RegExp(targetStr, "g");
    var newS = sourceStr.replace(regExp,"a");
}else if(SnoKmojime === "B"){
    var sourceStr = S;
    var targetStr = SnoKmojime;
    var regExp = new RegExp(targetStr, "g");
    var newS = sourceStr.replace(regExp,"b");
}else if(SnoKmojime === "C"){
    var sourceStr = S;
    var targetStr = SnoKmojime;
    var regExp = new RegExp(targetStr, "g");
    var newS = sourceStr.replace(regExp,"c");
}