本文整理汇总了PHP中RandomGenerator::generateOne方法的典型用法代码示例。如果您正苦于以下问题:PHP RandomGenerator::generateOne方法的具体用法?PHP RandomGenerator::generateOne怎么用?PHP RandomGenerator::generateOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RandomGenerator
的用法示例。
在下文中一共展示了RandomGenerator::generateOne方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testOne
public function testOne()
{
$output = RandomGenerator::generateOne();
$this->assertRegExp('/^([a-zA-Z0-9]{10})$/', $output, 'First match did not happen');
$output = RandomGenerator::generateOne(7, RandomGenerator::TYPE_ALPHA, 'blaXbla');
$this->assertRegExp('/^bla([a-zA-Z]{7})bla$/', $output, 'Second match did not happen');
$output = RandomGenerator::generateOne(6, RandomGenerator::TYPE_NUM, 'prefix-X-suffix', 2, '-');
$this->assertRegExp('/^prefix-([0-9-]{8})-suffix$/', $output, 'Separator match did not happen');
$output = RandomGenerator::generateOne(1200, RandomGenerator::TYPE_NUM);
$this->assertEquals(1200, strlen($output), 'Long string generated correctly');
}
示例2: generateCode
/**
* Uses the RandomGenerator engine to set the $this->code property
*
* @param int $length
* @param string $type
* @param string $pattern
* @param int $separateEvery
* @param string $separator
* @return mixed
*/
public function generateCode($length = 10, $type = RandomGenerator::TYPE_ALPHANUM, $pattern = 'X', $separateEvery = 0, $separator = '-')
{
//save random generation data in memory
$this->setMeta('random', array('length' => $length, 'type' => $type, 'pattern' => $pattern, 'separateEvery' => $separateEvery, 'separator' => $separator));
return $this->code = RandomGenerator::generateOne($length, $type, $pattern, $separateEvery, $separator);
}