Random Code(Color Hex Generator)
![SurveyBuilder-Admin](https://flatboard.org/uploads/avatars/SurveyBuilder-Admin_58600212.png)
Random Code(Color Hex Generator)
SurveyBuilder-Admin Wednesday 21st June 2023, 17:58:14I don't know why I am doing this, but I have made a custom HEX color generator
<?php
//$loop is how many generated hex code you would want to have.
function genHex(int $loop):array {
$hex = array();
$list = '0123456789abcdef';
for($i=0;$i<$loop;$i++){
$h='#';
for($k=0;$k<6;$k++){
$rand = rand(0,strlen($list)-1);
$l = str_split($list);
$h.=$l[$rand];
}
$hex[$h] = $h;
}
return $hex;
}
?>
Last modified by SurveyBuilder-Admin on Thursday 22nd June 2023, 11:50:00
Software engineer, creates plugins for Flatboard, checks source codes, and answers any software errors questions and contributes on the GitHub page as well
Replies 3
![simon](https://flatboard.org/uploads/avatars/simon_20a65f4f.png)
That's great, but you can do it more simply like this 😄 :
function genHex(int $loop): array {
$hexArray = [];
for ($i = 0; $i < $loop; $i++) {
$hexArray[] = sprintf('#%06X', mt_rand(0, 0xFFFFFF));
}
return $hexArray;
}
Last modified by Simon on Sunday 25th June 2023, 17:28:00
![SurveyBuilder-Admin](https://flatboard.org/uploads/avatars/SurveyBuilder-Admin_58600212.png)
I was always told that simple is lazy work. 😂
I don't know why, I take the longest and more complex why, then I should have attended,
Thanks for the "shorted version" of it.
I don't know why, I take the longest and more complex why, then I should have attended,
"if it works, then it's fine"
Thanks for the "shorted version" of it.
Last modified by SurveyBuilder-Admin on Sunday 25th June 2023, 18:49:00
Software engineer, creates plugins for Flatboard, checks source codes, and answers any software errors questions and contributes on the GitHub page as well
Suggested Topics
![](https://flatboard.org/uploads/avatars/generates/2a8ca3ea9x50dot.png)
Abdulhalim
started translation Persian language
General Questions
![](https://flatboard.org/uploads/avatars/generates/c4a1f8f94x50dot.png)
5.4K
5
![Ben](https://flatboard.org/uploads/avatars/generates/6cb01ce90x50dot.png)
Ben@84171e7c
started Emjois will pop up automatically in the wrong places: URLS and Code
Bug reports
![Fred](https://flatboard.org/uploads/avatars/Fred_4346f29d.png)
Fred
started tips Some rules against identity theft
Announcements