本文整理汇总了PHP中Random::int方法的典型用法代码示例。如果您正苦于以下问题:PHP Random::int方法的具体用法?PHP Random::int怎么用?PHP Random::int使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Random
的用法示例。
在下文中一共展示了Random::int方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
public static function get()
{
if (!isset(self::$rand_seeder)) {
//if ((PHP_SAPI == 'cli') or defined('STDIN')) {
if (IS_CLI) {
// CodeIgniter specific implementation.
self::$rand_seeder = Random::int(0, 2147483647);
} else {
//if (function_exists('get_instance')) {
// CodeIgniter specific implementation.
$ci = get_instance();
$ci->load->library('session');
$session_data = $ci->session->userdata('rand_seeder');
if (!is_null($session_data)) {
self::$rand_seeder = $session_data;
} else {
self::$rand_seeder = Random::int(0, 2147483647);
$ci->session->set_userdata('rand_seeder', self::$rand_seeder);
}
//} else {
// if (isset($_SESSION['rand_seeder'])) {
// self::$rand_seeder = $_SESSION['rand_seeder'];
// } else {
// self::$rand_seeder = rand();
// $_SESSION['rand_seeder'] = self::$rand_seeder;
// }
//}
}
}
return self::$rand_seeder;
}
示例2: bin2hex
<h4>PHP Implementation Tests</h4>
<?php
$my_random_boolean = Random::boolean() ? 1 : 0;
$result_true = 0;
$result_false = 0;
for ($i = 1; $i <= 100; $i++) {
if (Random::boolean()) {
$result_true++;
} else {
$result_false++;
}
}
$my_random_bytes = bin2hex(Random::bytes(10));
$my_random_float = Random::float();
$my_random_integer = Random::int(0, PHP_INT_MAX);
$my_random_integer_2 = Random::int(1, 100);
$my_random_string = Random::string(20);
$my_random_string_2 = Random::string(20, "!\"#\$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~");
?>
<table class="table table-bordered" style="table-layout: fixed; word-wrap: break-word;">
<tbody>
<tr>
<td style="width: 50%;"><pre><code>$my_random_boolean = Random::boolean() ? 1 : 0;</code></pre></td>
<td><?php
echo $my_random_boolean;
?>
</td>
</tr>
<tr>
<td><pre><code>$result_true = 0;
$result_false = 0;
示例3: testType
public function testType()
{
$this->assertTrue(is_int(Random::int(0, 10)));
}