We need an algorithm for generating random words in English, not necessarily with a meaning, the main thing is that these words are easy to read (alternation of vowels and consonants)
- You probably to the philologists. - VladD
- 3@Fanrin you forgot to add a few words, I highlighted them in bold. -------------------------------------------------- ------------ We need an algorithm for generating random words in English, not necessarily with a meaning, the main thing is that these words are easy to read (alternation of vowels and consonants) Write a script for me please !!! - Palmervan
|
2 answers
Like this:
$glas = ["a","e","i","y","o","u"]; $soglas = ["b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","x","w","z"]; $wordlen = 5; for ($i=0; $i <$wordlen/2 ; $i++) { $ng = rand(0, count($glas) - 1); $nsg = rand(0, count($soglas) - 1); $newWord .= $glas[$ng].$soglas[$nsg]; } echo $newWord;
- You can also add an array of the most frequently combined 2sec (3ec ..), for example ea, ee, th, ... And combine, taking into account the last letter of the two, if she agrees, the next vowel and vice versa .... - vv2cc
- Of course, but if I understood correctly, there’s no need to bother. =) - abibock_un
- Thank! Only here the array is not so declared in PHP) - Fanrin
- @Fanrin> Thank you! Only here the array is not so declared in PHP). Starting with PHP 5.4, it is possible to use the short array definition syntax, which replaces the language construct array () with []. - mantigatos
|
We have two arrays: vowels and consonants.
In the loop with each iteration, we first get from one random element, then from another.
Number of iterations set randomly. This is the easiest option :)
- And you can immediately write an array with all variants of syllables - Sugar
|