-
문자를 삽입하여 문자열을 스푸핑하고 싶습니다. 나는 수업했습니다 :임의의 개체에서 더 많은 고유 번호를 얻는 방법
static class Spoofer {
private static char spoofChar = '-';
private static Random rnd = new Random();
public static double SpoofPercentage = 0.3;
public static string Spoof(string input) {
if (input.Length == 0)
return "";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < input.Length; i++) {
while (rnd.NextDouble() <= SpoofPercentage) {
sb.Append(spoofChar);
}
sb.Append(input[i]);
}
return sb.ToString();
}
}
그리고 이것은 내가 스푸핑을 사용하는 방법입니다 :
의 모습 스푸핑 된 메시지입니다string messageToSpoof = "This is my example message";
string spoofedMessage = Spoofer.Spoof(messageToSpoof);
같은 : 당신이 -
이 볼 수 있듯이 그래서
-Th-is is my- e--x-am--p--l-e messa-g-e
--T-his is --my --exampl--e me--s-sage
This --is my exam--p-le mes-sage
This- -i-s m-y-- example-- ---mess---a---ge
Th-is is my example -message
Th-i----s is m-y- exam-p-le -message
This is-- -my examp--l--e me-ssa-g-e
This -is --my- e-xa--mple m----ess-age
T-his -is--- my- exa-m-ple me---s-s-ag-e
무작위로 삽입 된 것은 아닙니다. 패턴을 관찰하는 것은 쉽습니다. 대부분의 경우 -
은 몇 번 배치됩니다. 어떻게 피할 수 있습니까? 문제가 있다고 생각하면 Random
개체가 비슷한 값을 생성합니다.
어떤 패턴을 관찰하고 있습니까? – SLaks
알고리즘이 주어진 문자열에서 상당히 제한된 수의 대시를 생성하므로 패턴이 너무 많다고 생각하지 않습니다. '랜덤 '은 문제가 있지만, 지금은 당신이 그걸 때리는 것 같지 않습니다. – BradleyDotNET
'-'은 그룹으로되어 있습니다. 그것의 무작위 삽입 아닙니다. –