/** * Generate a hashid based on random data. * * @param null $salt * * @return string */ function generate_hashid($salt = null) { if (empty($salt)) { $salt = config('key'); } $hashids = new Hashids($salt); $min = rand(1, 1000) * rand(1, 1000); $max = rand(1, 1000) * rand(1, 1000); $quantity = rand(1, 64); $numbers = unique_random_numbers_within_range($min, $max, $quantity); return StaticStringy::truncate(StaticStringy::shuffle($hashids->encode($numbers)), 8); }
/** * @dataProvider shuffleProvider() */ public function testShuffle($str, $encoding = null) { $result = S::shuffle($str, $encoding); $encoding = $encoding ?: mb_internal_encoding(); $this->assertInternalType('string', $result); $this->assertEquals(mb_strlen($str, $encoding), mb_strlen($result, $encoding)); // We'll make sure that the chars are present after shuffle for ($i = 0; $i < mb_strlen($str, $encoding); $i++) { $char = mb_substr($str, $i, 1, $encoding); $countBefore = mb_substr_count($str, $char, $encoding); $countAfter = mb_substr_count($result, $char, $encoding); $this->assertEquals($countBefore, $countAfter); } }
public function shuffle($string) { return Stringy::shuffle($string); }