How to create a folder with a unique name from a list of characters?

0 like 0 dislike
3 views
Need a script that generates the folder name from two lists of symbols - consonants and vowels
see if there is already such a folder on the server

we need to create a folder which has no

a list of consonants: FDTRWQK
a list of consonants: OEAIU
the sequence of letters of the name must be of the form: DADADA
that is, consonants and vowels

$m_1 = array("D", "B", "G", "V", "Z", "J", "R", "L", "M", "N", "H", "C"); $m_2 = array("A", "O", "E", "U", "I"); do { $name = $m_1[array_rand($m_1, 1)] . $m_2[array_rand($m_2, 1)] . $m_1[array_rand($m_1, 1)] . $m_2[array_rand($m_2, 1)] . $m_1[array_rand($m_1, 1)] . $m_2[array_rand($m_2, 1)]; } while (file_exists('folder/'.$name)); mkdir('folder/'.$name);
by | 3 views

2 Answers

0 like 0 dislike
by
0 like 0 dislike
array_rand() randomic sucks, just rand()

At least a couple of years ago, it ran, array_rand() has started to give out patterns that may or cyclical.

Use
\rphp.net/manual/ru/function.random-int.php

Something on the subject https://habr.com/post/272509/
there is an example of a function obtaining a random string from given characters.
by
110,608 questions
257,186 answers
0 comments
33,901 users