Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
                        <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;
Ejemplo n.º 3
0
 public function testType()
 {
     $this->assertTrue(is_int(Random::int(0, 10)));
 }