本文整理汇总了PHP中Random::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Random::get方法的具体用法?PHP Random::get怎么用?PHP Random::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Random
的用法示例。
在下文中一共展示了Random::get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GenerateRandomPrintableString
function GenerateRandomPrintableString($len = 10)
{
$o1 = new Random("23456789ABCDEFGHJKMNPQRSTUVWXYZ");
return $o1->get($len);
}
示例2: rolltype
public function rolltype($dietype)
{
if (is_numeric($dietype)) {
$newval = Random::get(1, $dietype);
} elseif ($dietype == 'f') {
$newval = Random::get(-1, 1);
} elseif ($dietype == '%') {
$newval = Random::get(1, 100);
} elseif ($dietype[0] == '[') {
$dietype = trim($dietype, '[]');
$opts = explode(',', $dietype);
$newval = $opts[Random::get(0, count($opts)-1)];
} else {
var_dump($dietype);
$newval = 'unknown';
}
return $newval;
}
示例3: get
/**
* Generate random characters
*
* @access public
* @param int $len Length of the string you want generated
* @return string Random characters
*/
function get($len)
{
if (!(is_int($len) && $len > 0)) {
return $this->_vcrs;
}
$ret = "";
$cnt = strlen($this->_vcrs) - 1;
for ($i = 0; $i < $len; $i++) {
$ret .= $this->_vcrs[rand(0, $cnt)];
}
if ($this->_vnum || $this->_vnot) {
return $this->_rec($ret, $this->_vnum, $this->_vnot) ? $ret : Random::get($len);
} else {
return $ret;
}
}
示例4: testExceptionIfAskedForMoreThen20Chars
/**
* @expectedException ShortCode\Exception\UnexpectedCodeLength
*/
public function testExceptionIfAskedForMoreThen20Chars()
{
Random::get(25, Code::FORMAT_NUMBER);
}
示例5:
<td><span id="my_random_integer_number_2"> </span></td>
</tr>
<tr>
<td><pre><code>var my_unique_id = $.random.uuid();</code></pre></td>
<td><span id="my_unique_id"> </span></td>
</tr>
</tbody>
</table>
</div>
<div class="col-md-6">
<h4>PHP Implementation Tests</h4>
<?php
$my_random_number = Random::get();
$my_random_integer_number = Random::integer(10);
$my_random_integer_number_2 = Random::integer_between(10, 19);
$my_unique_id = Random::uuid();
?>
<table class="table table-bordered" style="table-layout: fixed; word-wrap: break-word;">
<tbody>
<tr>
<td style="width: 50%;"><pre><code>$my_random_number = Random::get();</code></pre></td>
<td><?php
echo $my_random_number;
?>
</td>
</tr>
<tr>
<td><pre><code>$my_random_integer_number = Random::integer(10);</code></pre></td>
示例6: testCodeGeneratedWithCorrectFormat
/**
* @dataProvider formatProvider
*
* @param $format
* @param $formatName
*/
public function testCodeGeneratedWithCorrectFormat($format, $formatName)
{
$code = Random::get(6, $format);
$length = strlen($code);
$this->assertSame(1, preg_match("/[{$format}]{" . $length . '}/', $code), 'Trying with ' . $formatName);
}