function GenerateRandomPrintableString($len = 10)
 {
     $o1 = new Random("23456789ABCDEFGHJKMNPQRSTUVWXYZ");
     return $o1->get($len);
 }
Example #2
0
    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;
    }
 /**
  * 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;
     }
 }
Example #4
0
 /**
  * @expectedException ShortCode\Exception\UnexpectedCodeLength
  */
 public function testExceptionIfAskedForMoreThen20Chars()
 {
     Random::get(25, Code::FORMAT_NUMBER);
 }
Example #5
0
                                    <td><span id="my_random_integer_number_2">&nbsp;</span></td>
                                </tr>
                                <tr>
                                    <td><pre><code>var my_unique_id = $.random.uuid();</code></pre></td>
                                    <td><span id="my_unique_id">&nbsp;</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>
Example #6
0
 /**
  * @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);
 }