random($step); // NOTE: `$bytes` maybe not a normal "Array" // sometimes it's begin from index 1, use iterator please foreach ($bytes as $byte) { $byte &= $mask; if (isset($alphabet[$byte])) { $id .= $alphabet[$byte]; if (strlen($id) === $size) { return $id; } } } } } }