有在ho中存在差異w「等效」的php函數可以工作,所以這裏有問題,具體是pickOne()
的計算。 Math.random()
與random()
的作用不一樣,所以編號就沒有了。看看這是否讓你更接近。一個說明,日本字符造成如此認爲它的垃圾郵件,所以我離開了這些出來,但他們確實需要在這些數組來填充:
class Characters
{
private $mugenzaru;
public function getString(Mugenzaru $mugenzaru,$charType = 'kangi')
{
$this->mugenzaru = $mugenzaru;
$kanji = array(2, 2, 2, 2, 2, 2, 1, 1, 1, 3, 3, 4);
$hiragana = array(1, 1, 1, 1, 2, 2, 2, 3, 3, 4);
$katakana = array(2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 6, 6, 7);
$punctuation = array(1);
$lengthWeighting = ${$charType};
$charStringLength = $this->mugenzaru->eenieMeenie()->pickOne($lengthWeighting);
$resultString = "";
while ($charStringLength != 0) {
$resultString .= $this->mugenzaru->eenieMeenie()->pickOne($this->mugenzaru->{$charType}());
$charStringLength--;
}
return $resultString;
}
}
class EenieMeenie
{
public function pickOne($characterList)
{
$rand = "0.".str_pad(mt_rand(1,9999999999999999),16,0,STR_PAD_LEFT);
$var = floor($rand*count($characterList));
return $characterList[$var];
}
}
class Mugenzaru
{
private $length = 10;
public function eenieMeenie()
{
return new EenieMeenie();
}
public function __call($name, $args = false)
{
$kanji = array(/*** array of kanji ***/);
$hiragana = array(/*** array of hiragana ***/);
$katakana = array(/*** array of katakana ***/);
$punctuation = array(/*** array of punctuation ***/);
return ${$name};
}
public function setLength($num = 1000)
{
$this->length = $num;
return $this;
}
public function doIt(Characters $char) {
$weighting = array(1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 4, 4);
$resultString = "";
$targetLength = $this->length;
while(strlen($resultString) < $targetLength) {
$charWeight = $this->eenieMeenie()->pickOne($weighting);
switch ($charWeight){
case 1:
$resultString .= $char->getString($this,'kanji');
break;
case 2:
$resultString .= $char->getString($this,'hiragana');
break;
case 3:
$resultString .= $char->getString($this,'katakana');
break;
case 4:
$resultString .= $char->getString($this,'punctuation');
break;
default:
$resultString .= $char->getString($this,'kanji');
}
}
return $resultString;
}
}
$Mugenzaru = new Mugenzaru();
echo $Mugenzaru->setLength(1000)->doIt(new Characters);
注:代碼必須張貼幷包含在你的問題 – Ghost
我想如果將函數移動到類中,您將獲得更多成功。 – Rasclatt
@Ghost 根據Rasclatt的說法,我似乎不能包含代碼bc它包含觸發垃圾郵件警報的日文字符。 –