Created
January 23, 2020 23:05
-
-
Save ArbahudRioDaroyni/d40f8dae86b5a2e84c54e35a452eb7f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class Lorem { | |
public static function paragraphs($nparagraphs) { | |
$paragraphs = []; | |
for($p = 0; $p < $nparagraphs; ++$p) { | |
$nsentences = random_int(3, 8); | |
$sentences = []; | |
for($s = 0; $s < $nsentences; ++$s) { | |
$frags = []; | |
$commaChance = .33; | |
while(true) { | |
$nwords = random_int(3, 15); | |
$words = self::random_values(self::$lorem, $nwords); | |
$frags[] = implode(' ', $words); | |
if(self::random_float() >= $commaChance) { | |
break; | |
} | |
$commaChance /= 2; | |
} | |
$sentences[] = ucfirst(implode(', ', $frags)) . '.'; | |
} | |
$paragraphs[] = implode(' ', $sentences); | |
} | |
return implode("<br><br>", $paragraphs); | |
} | |
public function name($nname) | |
{ | |
$name = ""; | |
$names = array_rand(self::$lorem, $nname); | |
$name .= self::$lorem[$names[0]]; | |
for ($i=1; $i < $nname; $i++) { | |
$name .= " " . self::$lorem[$names[$i]]; | |
} | |
return $name; | |
} | |
private static function random_float() { | |
return random_int(0, PHP_INT_MAX - 1) / PHP_INT_MAX; | |
} | |
private static function random_values($arr, $count) { | |
$keys = array_rand($arr, $count); | |
if($count == 1) { | |
$keys = [$keys]; | |
} | |
return array_intersect_key($arr, array_fill_keys($keys, null)); | |
} | |
private static $lorem = ['lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit', 'praesent', 'interdum', 'dictum', 'mi', 'non', 'egestas', 'nulla', 'in', 'lacus', 'sed', 'sapien', 'placerat', 'malesuada', 'at', 'erat', 'etiam', 'id', 'velit', 'finibus', 'viverra', 'maecenas', 'mattis', 'volutpat', 'justo', 'vitae', 'vestibulum', 'metus', 'lobortis', 'mauris', 'luctus', 'leo', 'feugiat', 'nibh', 'tincidunt', 'a', 'integer', 'facilisis', 'lacinia', 'ligula', 'ac', 'suspendisse', 'eleifend', 'nunc', 'nec', 'pulvinar', 'quisque', 'ut', 'semper', 'auctor', 'tortor', 'mollis', 'est', 'tempor', 'scelerisque', 'venenatis', 'quis', 'ultrices', 'tellus', 'nisi', 'phasellus', 'aliquam', 'molestie', 'purus', 'convallis', 'cursus', 'ex', 'massa', 'fusce', 'felis', 'fringilla', 'faucibus', 'varius', 'ante', 'primis', 'orci', 'et', 'posuere', 'cubilia', 'curae', 'proin', 'ultricies', 'hendrerit', 'ornare', 'augue', 'pharetra', 'dapibus', 'nullam', 'sollicitudin', 'euismod', 'eget', 'pretium', 'vulputate', 'urna', 'arcu', 'porttitor', 'quam', 'condimentum', 'consequat', 'tempus', 'hac', 'habitasse', 'platea', 'dictumst', 'sagittis', 'gravida', 'eu', 'commodo', 'dui', 'lectus', 'vivamus', 'libero', 'vel', 'maximus', 'pellentesque', 'efficitur', 'class', 'aptent', 'taciti', 'sociosqu', 'ad', 'litora', 'torquent', 'per', 'conubia', 'nostra', 'inceptos', 'himenaeos', 'fermentum', 'turpis', 'donec', 'magna', 'porta', 'enim', 'curabitur', 'odio', 'rhoncus', 'blandit', 'potenti', 'sodales', 'accumsan', 'congue', 'neque', 'duis', 'bibendum', 'laoreet', 'elementum', 'suscipit', 'diam', 'vehicula', 'eros', 'nam', 'imperdiet', 'sem', 'ullamcorper', 'dignissim', 'risus', 'aliquet', 'habitant', 'morbi', 'tristique', 'senectus', 'netus', 'fames', 'nisl', 'iaculis', 'cras', 'aenean']; | |
} | |
// Usage | |
// echo Lorem::name(2); | |
// echo Lorem::paragraphs(2); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment