*/
public static function random($length = 0)
{
- // custom high and lows
- if (is_array($length))
- {
- $length = rand($length[0], $length[1]);
- }
- else if (!$length)
+ // length wasn't provided, so create our own
+ if ($length < 1)
{
$length = rand(20, 65);
}
public function testRandom()
{
+ // test fixed length
$values = array();
for ($i = 0; $i < 100; $i++)
{
$random = BSFunctions::random(5);
$this->assertEquals(5, strlen($random));
- $this->assertFalse(in_array($random, $values));
$values[] = $random;
}
+ $this->assertEquals(sizeof(array_unique($values)), sizeof($values));
+
+ // test random length
+ $values = array();
+ for ($i = 0; $i < 100; $i++)
+ {
+ $random = BSFunctions::random();
+ $length = strlen($random);
+ $this->assertTrue($length >= 20 && $length <= 65);
+ $values[] = $random;
+ }
+ $this->assertEquals(sizeof(array_unique($values)), sizeof($values));
}
public function testArraySetCurrent()