/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     factory(Eggdrop::class, 200)->create()->each(function ($egg) {
         $egg->servers()->attach(random_int(1, 2));
         $egg->servers()->attach(3);
     });
 }
 /**
  * Birthday spacings: Choose random points on a large interval. 
  * The spacings between the points should be asymptotically exponentially
  * distributed.
  */
 public function testBirthday()
 {
     // Number of buckets to make
     $num_buckets = 17;
     // How much tolerance should we allow? 0.01 = 1% 0.50 = 50%, etc.
     $tolerance = 0.03;
     $rand_min = 200000;
     $rand_max = 600000;
     $rand_step = 100000;
     $minT = 1.0 - $tolerance;
     $maxT = 1.0 + $tolerance;
     for ($nums_to_generate = $rand_min; $nums_to_generate < $rand_max; $nums_to_generate += $rand_step) {
         $buckets = array_fill(0, $num_buckets, 0);
         // The number of ints we expect per bucket +/- 2%;
         $min = (int) ceil($minT * $nums_to_generate / $num_buckets);
         $max = (int) floor($maxT * $nums_to_generate / $num_buckets);
         for ($i = 0; $i < $nums_to_generate; ++$i) {
             $random = random_int(0, 999);
             $bucket = $random % $num_buckets;
             $buckets[$bucket]++;
         }
         for ($i = 0; $i < $num_buckets; ++$i) {
             // Debugging code:
             if ($buckets[$i] <= $min) {
                 var_dump(['bucket' => $i, 'value' => $buckets[$i], 'min' => $min, 'nums' => $nums_to_generate, 'reason' => 'below min']);
             }
             if ($buckets[$i] >= $max) {
                 var_dump(['bucket' => $i, 'value' => $buckets[$i], 'maax' => $max, 'nums' => $nums_to_generate, 'reason' => 'above max']);
             }
             $this->assertTrue($buckets[$i] < $max && $buckets[$i] > $min);
         }
     }
 }
Esempio n. 3
0
 public function testOutput()
 {
     $half_neg_max = ~PHP_INT_MAX / 2;
     $integers = array(random_int(0, 1000), random_int(1001, 2000), random_int(-100, -10), random_int(-1000, 1000), random_int(~PHP_INT_MAX, PHP_INT_MAX), random_int("0", "1"), random_int(0.11111, 0.99999), random_int($half_neg_max, PHP_INT_MAX), random_int(0.0, 255.0), random_int(-4.5, -4.5));
     $this->assertFalse($integers[0] === $integers[1]);
     $this->assertTrue($integers[0] >= 0 && $integers[0] <= 1000);
     $this->assertTrue($integers[1] >= 1001 && $integers[1] <= 2000);
     $this->assertTrue($integers[2] >= -100 && $integers[2] <= -10);
     $this->assertTrue($integers[3] >= -1000 && $integers[3] <= 1000);
     $this->assertTrue($integers[4] >= ~PHP_INT_MAX && $integers[4] <= PHP_INT_MAX);
     $this->assertTrue($integers[5] >= 0 && $integers[5] <= 1);
     $this->assertTrue($integers[6] === 0);
     $this->assertTrue($integers[7] >= $half_neg_max && $integers[7] <= PHP_INT_MAX);
     $this->assertTrue($integers[8] >= 0 && $integers[8] <= 255);
     $this->assertTrue($integers[9] === -4);
     try {
         $i = random_int("9223372036854775808", "9223372036854775807");
         $this->assertFalse(is_int($i));
         $i = random_int("-9223372036854775808", "9223372036854775807");
         $this->assertFalse(true);
     } catch (Error $ex) {
         $this->assertTrue($ex instanceof Error);
     } catch (Exception $ex) {
         $this->assertTrue($ex instanceof Exception);
     }
 }
 public function add_message(Request $request)
 {
     $item = new Item();
     $item->id = random_int(0, 1000);
     $item->text = $request->get('message', 'you send empty text....');
     Event::fire(new ItemCreated($item));
 }
Esempio n. 5
0
 public static function get_new_salts()
 {
     // From wp-admin/setup-config.php in WordPress 4.5.
     // Generate keys and salts using secure CSPRNG; fallback to API if enabled; further fallback to original wp_generate_password().
     try {
         $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|';
         $max = strlen($chars) - 1;
         for ($i = 0; $i < 8; $i++) {
             $key = '';
             for ($j = 0; $j < 64; $j++) {
                 $key .= substr($chars, random_int(0, $max), 1);
             }
             $secret_keys[] = $key;
         }
     } catch (Exception $ex) {
         $secret_keys = wp_remote_get('https://api.wordpress.org/secret-key/1.1/salt/');
         if (is_wp_error($secret_keys)) {
             $secret_keys = array();
             for ($i = 0; $i < 8; $i++) {
                 $secret_keys[] = wp_generate_password(64, true, true);
             }
         } else {
             $secret_keys = explode("\n", wp_remote_retrieve_body($secret_keys));
             foreach ($secret_keys as $k => $v) {
                 $secret_keys[$k] = substr($v, 28, 64);
             }
         }
     }
     return $secret_keys;
 }
 public static function generate_captcha() : string
 {
     $num1 = random_int(self::CAPTCHA_NUMBER_MIN, self::CAPTCHA_NUMBER_MAX);
     $num2 = random_int(self::CAPTCHA_NUMBER_MIN, self::CAPTCHA_NUMBER_MAX);
     switch (random_int(0, 3)) {
         case 0:
             $max = max($num1, $num2);
             $min = min($num1, $num2);
             $answer = $max - $min;
             $question = "{$max} - {$min} =";
             break;
         case 1:
             $answer = $num1;
             $squared = $num1 * $num1;
             $question = "&radic;{$squared} =";
             break;
         case 2:
             $answer = $num1 * $num2;
             $question = "{$num1} &times; {$num2} =";
             break;
         default:
             $answer = $num1 + $num2;
             $question = "{$num1} + {$num2} =";
             break;
     }
     $_SESSION[self::SESSION_CAPTCHA_ANSWER_KEY] = $answer;
     return $question;
 }
Esempio n. 7
0
 public function getTest()
 {
     $numberInitial = 200;
     $numberMarried = floor($numberInitial * 10 / 100);
     $genders = [Personnage::GENDER_FEMALE, Personnage::GENDER_MALE];
     $chars = new Collection();
     for ($i = 0; $i < $numberInitial; $i++) {
         $char = new Personnage();
         $chars->push($char);
         $char->setGender($genders[array_rand($genders)]);
         $char->setAge(random_int(1, 60));
         $char->setName($i);
     }
     //Create some marriages
     foreach ($chars as $char) {
         if ($char->age > 15) {
             $numberMarried--;
             $spouse = new Personnage();
             $spouse->setAge(max(15, random_int($char->age - 5, $char->age + 5)));
             $spouse->setGender($char->gender == Personnage::GENDER_MALE ? Personnage::GENDER_FEMALE : Personnage::GENDER_MALE);
             $spouse->setName("Spouse {$numberMarried}");
             $relation = new MarriedTo($spouse, $char);
             $spouse->addRelation($relation);
             $chars->push($spouse);
             //Get them some babies!
             $totalBabies = random_int(0, min(abs($char->age - $spouse->age), 5));
             $siblings = [];
             for ($i = 0; $i < $totalBabies; $i++) {
                 $child = new Personnage();
                 $child->setGender($genders[array_rand($genders)]);
                 $child->setName("Child {$numberMarried}.{$i}");
                 $relation1 = new ParentOf($char, $child);
                 $relation2 = new ParentOf($spouse, $child);
                 $char->addRelation($relation1);
                 $spouse->addRelation($relation2);
                 $chars->push($child);
                 foreach ($siblings as $sibling) {
                     $relation = new SiblingOf($sibling, $child);
                     $sibling->addRelation($relation);
                 }
                 $siblings[] = $child;
             }
         }
         if ($numberMarried <= 0) {
             break;
         }
     }
     /*$man1 = new Personnage();
             $woman1 = new Personnage();
     
             $man1->setName('man1');
             $woman1->setName('woman1');
     
             $man1->setAge(random_int(20, 50));
             $woman1->setAge(max(15,random_int($man1->age - 5, $man1->age + 5)));
     
             $married = new MarriedTo($man1, $woman1);
             $man1->addRelation($married);*/
     echo implode('<br/>', $chars->toArray());
 }
Esempio n. 8
0
 /**
  * @return string
  */
 public function getID() : string
 {
     if ($this->routeID === null) {
         $this->routeID = sprintf('%012x%04x%04x%012x', random_int(0, 0xffffffffffff), random_int(0, 0xfff) | 0x4000, random_int(0, 0x3fff) | 0x8000, random_int(0, 0xffffffffffff));
     }
     return $this->routeID;
 }
 function __construct($id)
 {
     $this->id = str_replace('-', '_', $id);
     // necessary to ensure we don't have ID collisions in the SQL
     $this->row_iterator = 0;
     $this->random_int = random_int(1, 1000000);
 }
Esempio n. 10
0
 public function testTrackedTimeGetsSummarizedCorrectlyForTask()
 {
     $timediff_seconds1 = random_int(10, 9999);
     $now = date('Y-m-d H:i:s');
     $start1 = new \DateTime($now);
     $stop1 = new \DateTime($now);
     $dateinterval1 = new \DateInterval("PT{$timediff_seconds1}S");
     $stop1->add($dateinterval1);
     factory(Tracking::class)->create(['user_id' => $this->user->id, 'task_id' => $this->task1->id, 'started_at' => $start1->format('Y-m-d H:i:s'), 'stopped_at' => $stop1->format('Y-m-d H:i:s'), 'active' => false]);
     $timediff_seconds2 = random_int(10, 9999);
     $yesterday = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('n'), date('j') - 1, date('Y')));
     $start2 = new \DateTime($yesterday);
     $stop2 = new \DateTime($yesterday);
     $dateinterval2 = new \DateInterval("PT{$timediff_seconds2}S");
     $stop2->add($dateinterval2);
     factory(Tracking::class)->create(['user_id' => $this->user->id, 'task_id' => $this->task1->id, 'started_at' => $start2->format('Y-m-d H:i:s'), 'stopped_at' => $stop2->format('Y-m-d H:i:s'), 'active' => false]);
     $timediff_seconds3 = random_int(10, 9999);
     $twodaysbefore = date('Y-m-d H:i:s', mktime(date('H'), date('i'), date('s'), date('n'), date('j') - 1, date('Y')));
     $start3 = new \DateTime($twodaysbefore);
     $stop3 = new \DateTime($twodaysbefore);
     $dateinterval3 = new \DateInterval("PT{$timediff_seconds3}S");
     $stop3->add($dateinterval3);
     factory(Tracking::class)->create(['user_id' => $this->user->id, 'task_id' => $this->task1->id, 'started_at' => $start3->format('Y-m-d H:i:s'), 'stopped_at' => $stop3->format('Y-m-d H:i:s'), 'active' => false]);
     $start_expected_calculation = new \DateTime($now);
     $stop_expected_calculation = new \DateTime($now);
     $stop_expected_calculation->add(new \DateInterval('PT' . ($timediff_seconds1 + $timediff_seconds2 + $timediff_seconds3) . 'S'));
     $expected_dateinterval = $start_expected_calculation->diff($stop_expected_calculation);
     $task = Task::where('id', 1);
     $this->assertEquals($expected_dateinterval, $this->task1->getTrackedTime());
 }
Esempio n. 11
0
 /**
  * @param \Orm\Zed\Sales\Persistence\SpySalesOrder $salesOrderEntity
  *
  * @return void
  */
 protected function addOrderDetails(SpySalesOrder $salesOrderEntity)
 {
     $salesOrderEntity->setOrderReference(random_int(0, 9999999));
     $salesOrderEntity->setIsTest(true);
     $salesOrderEntity->setSalutation(SpySalesOrderTableMap::COL_SALUTATION_MR);
     $salesOrderEntity->setFirstName('FirstName');
     $salesOrderEntity->setLastName('LastName');
 }
Esempio n. 12
0
 public function roll()
 {
     if (function_exists('random_int')) {
         $this->result = random_int(1, $this->sides);
     } else {
         $this->result = mt_rand(1, $this->sides);
     }
 }
Esempio n. 13
0
 public static function generate()
 {
     if (version_compare(PHP_VERSION, '7.0.0', '<')) {
         return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xfff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
     } else {
         return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', random_int(0, 0xffff), random_int(0, 0xffff), random_int(0, 0xffff), random_int(0, 0xfff) | 0x4000, random_int(0, 0x3fff) | 0x8000, random_int(0, 0xffff), random_int(0, 0xffff), random_int(0, 0xffff));
     }
 }
Esempio n. 14
0
 /**
  * @param int $numDice Number of D6's to roll
  * @return int
  */
 public function roll(int $numDice = 1)
 {
     $total = 0;
     for ($i = 0; $i < $numDice; $i++) {
         $total += random_int(1, $this->range);
     }
     return $total;
 }
Esempio n. 15
0
function rollDie($sides)
{
    if (function_exists('random_int')) {
        return random_int(1, $sides);
    } else {
        return mt_rand(1, $sides);
    }
}
Esempio n. 16
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('epizodes')->insert(['name' => str_random(50), 'description' => str_random(50), 'number' => random_int(1, 40), 'images' => 'example.jpg', 'producer' => str_random(10), 'directed' => str_random(10), 'running_time' => 100, 'season_id' => 1, 'serial_id' => 1, 'date_start' => date(1), 'slug' => str_random(10)]);
     DB::table('epizodes')->insert(['name' => str_random(50), 'description' => str_random(50), 'number' => random_int(1, 40), 'images' => 'example.jpg', 'producer' => str_random(10), 'directed' => str_random(10), 'running_time' => 100, 'season_id' => 1, 'serial_id' => 1, 'date_start' => date(1), 'slug' => str_random(10)]);
     DB::table('epizodes')->insert(['name' => str_random(50), 'description' => str_random(50), 'number' => random_int(1, 40), 'images' => 'example.jpg', 'producer' => str_random(10), 'directed' => str_random(10), 'running_time' => 100, 'season_id' => 1, 'serial_id' => 1, 'date_start' => date(1), 'slug' => str_random(10)]);
     DB::table('epizodes')->insert(['name' => str_random(50), 'description' => str_random(50), 'number' => random_int(1, 40), 'images' => 'example.jpg', 'producer' => str_random(10), 'directed' => str_random(10), 'running_time' => 100, 'season_id' => 3, 'serial_id' => 1, 'date_start' => date(1), 'slug' => str_random(10)]);
     DB::table('epizodes')->insert(['name' => str_random(50), 'description' => str_random(50), 'number' => random_int(1, 40), 'images' => 'example.jpg', 'producer' => str_random(10), 'directed' => str_random(10), 'running_time' => 100, 'season_id' => 3, 'serial_id' => 1, 'date_start' => date(1), 'slug' => str_random(10)]);
 }
Esempio n. 17
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     factory(Category::class, random_int(1, 5))->create();
     factory(Category::class, random_int(1, 10))->make()->each(function (Category $category) {
         $category->parent_id = Category::inRandomOrder()->first()->id;
         $category->save();
     });
 }
 /**
  * Generates a secret key!
  *
  * Interestingly, the easiest way to get truly random key is just to iterate through the base 32 chars picking random
  * characters
  */
 public function generateSecretKey()
 {
     $key = "";
     while (strlen($key) < $this->secretLength) {
         $key .= $this->base32Chars[random_int(0, 31)];
     }
     return $key;
 }
Esempio n. 19
0
 /**
  * @param int $min
  * @param int $max
  * @return int
  */
 private function getRandomNumber($min, $max)
 {
     // The function random_int was added in PHP 7.0
     if (function_exists('random_int')) {
         return random_int($min, $max);
     }
     return mt_rand($min, $max);
 }
Esempio n. 20
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('seasons')->insert(['serial_id' => 1, 'number' => random_int(1, 40), 'count_epizdes' => random_int(1, 40), 'country' => str_random(10), 'description' => str_random(50), 'date_start' => date(1), 'date_end' => date(1), 'slug' => str_random(10)]);
     DB::table('seasons')->insert(['serial_id' => 1, 'number' => random_int(1, 40), 'count_epizdes' => random_int(1, 40), 'country' => str_random(10), 'description' => str_random(50), 'date_start' => date(1), 'date_end' => date(1), 'slug' => str_random(10)]);
     DB::table('seasons')->insert(['serial_id' => 1, 'number' => random_int(1, 40), 'count_epizdes' => random_int(1, 40), 'country' => str_random(10), 'description' => str_random(50), 'date_start' => date(1), 'date_end' => date(1), 'slug' => str_random(10)]);
     DB::table('seasons')->insert(['serial_id' => 1, 'number' => random_int(1, 40), 'count_epizdes' => random_int(1, 40), 'country' => str_random(10), 'description' => str_random(50), 'date_start' => date(1), 'date_end' => date(1), 'slug' => str_random(10)]);
     DB::table('seasons')->insert(['serial_id' => 1, 'number' => random_int(1, 40), 'count_epizdes' => random_int(1, 40), 'country' => str_random(10), 'description' => str_random(50), 'date_start' => date(1), 'date_end' => date(1), 'slug' => str_random(10)]);
 }
Esempio n. 21
0
 public function testJsonSerializable()
 {
     $column = random_int(1, 10);
     $dir = Order::DESC;
     $expected = json_encode(['column' => $column, 'dir' => $dir]);
     $object = new Order($column, $dir);
     self::assertEquals($expected, json_encode($object));
 }
Esempio n. 22
0
function big_random_int($len = 18)
{
    $rand = '';
    while (!isset($rand[$len - 1])) {
        $rand .= random_int(0, 9999999);
    }
    return substr($rand, 0, $len);
}
Esempio n. 23
0
 function random_str($length, $keyspace = 'YZ0hijklmn12gopqr3MN4efstTUV56JKL7FGH8OPQ9abcduvwxyzABCDEIRSWX')
 {
     $str = '';
     $max = mb_strlen($keyspace, '8bit') - 1;
     for ($i = 0; $i < $length; ++$i) {
         $str .= $keyspace[random_int(0, $max)];
     }
     return $str;
 }
Esempio n. 24
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     factory(Post::class, 50)->create()->each(function ($item) {
         $users = User::all()->random(random_int(1, 10))->all();
         foreach ($users as $user) {
             $item->likes()->create(['user_id' => $user->id]);
         }
     });
 }
Esempio n. 25
0
function gen_str($length, $keyspace)
{
    $str = '';
    $max = mb_strlen($keyspace, '8bit') - 1;
    for ($i = 0; $i < $length; ++$i) {
        $str .= $keyspace[random_int(0, $max)];
    }
    return $str;
}
 /**
  * function copied from
  * http://stackoverflow.com/questions/4356289/php-random-string-generator
  *
  * @param $length int
  *
  * @return string
  */
 public static function randomString($length = 10) : int
 {
     $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
     $randomString = '';
     for ($i = 0; $i < $length; $i++) {
         $randomString .= $characters[random_int(0, strlen($characters) - 1)];
     }
     return $randomString;
 }
Esempio n. 27
0
 public function random_str($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
 {
     $str = '';
     $max = mb_strlen($keyspace, '8bit') - 1;
     for ($i = 0; $i < $length; ++$i) {
         $str .= $keyspace[random_int(0, $max)];
     }
     return $str;
 }
Esempio n. 28
0
 /**
  * Handle the analysis has completed event.
  *
  * We have a 1 in 8 chance of performing a cleanup.
  *
  * @param \StyleCI\StyleCI\Events\Analysis\AnalysisHasCompletedEvent $event
  *
  * @return void
  */
 public function handle(AnalysisHasCompletedEvent $event)
 {
     if (random_int(0, 7) > 0) {
         return;
     }
     foreach (Analysis::old()->pending()->orderBy('created_at', 'asc')->get() as $analysis) {
         $this->dispatch(new CleanupAnalysisJob($analysis));
     }
 }
Esempio n. 29
0
 public function testOutput()
 {
     $integers = array(random_int(0, 1000), random_int(1001, 2000), random_int(-100, -10), random_int(-1000, 1000));
     $this->assertFalse($integers[0] === $integers[1]);
     $this->assertTrue($integers[0] >= 0 && $integers[0] <= 1000);
     $this->assertTrue($integers[1] >= 1001 && $integers[1] <= 2000);
     $this->assertTrue($integers[2] >= -100 && $integers[2] <= -10);
     $this->assertTrue($integers[2] >= -1000 && $integers[2] <= 1000);
 }
Esempio n. 30
0
 /**
  * @param int $length
  * @param string $characters
  * @return string
  */
 public function generateString($length = 12, $characters = self::ALPHA_NUMERIC)
 {
     $randomString = "";
     for ($i = 0; $i < $length; $i++) {
         $index = random_int(0, strlen($characters) - 1);
         $randomString .= $characters[$index];
     }
     return $randomString;
 }