MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/pgrke2/assign_random_value/
r/badcode • u/RyanNerd shameless • Sep 02 '21
11 comments sorted by
8
Much random
5 u/RyanNerd shameless Sep 03 '21 Very accidental.
5
Very accidental.
11
The worst part is that the code comments have typos...
Retourne une valeur en fonction du nombre passeré en paramètre26 lettres10 chiffres10 caractères spéciaux
Retourne une valeur en fonction du nombre passeré en paramètre
26 lettres
10 chiffres
10 caractères spéciaux
5 u/the_captain_cat Sep 03 '21 That triggers me even more than the bad code
That triggers me even more than the bad code
16
The function name is wrong, but it does what the comment says.
return a value according to the number passed as parameter
5 u/Akantor47 Sep 03 '21 assign_rand_value(51) ?
assign_rand_value(51) ?
4
You can clearly see it's a private method. $pNum is being randomly generated somewhere else.
3
Its pseudorandom.
6 u/Frommelow Sep 03 '21 edited Sep 04 '21 Not even that. To be precise it's the exact opposite. It's completely deterministic.
6
Not even that. To be precise it's the exact opposite. It's completely deterministic.
Image Transcription: Code
class Random { /** * Retourne une valeur en fonction du nombre passer en parametre * * @param int $pNum * @return string charactere */ private static function assign_rand_value(int $pNum) { // 26 lettre // 10 chiffre // 10 caractere spéciaux $list = array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i' , 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '/', '!', '@', '#', '~', '%', '&', '-', '_' ); return $list[$pNum]; } }
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
8
u/Akantor47 Sep 02 '21
Much random
11
u/HipstCapitalist Sep 03 '21
The worst part is that the code comments have typos...
16
u/frayien Sep 03 '21
The function name is wrong, but it does what the comment says.
4
u/RedditAcc-92975 Sep 03 '21
You can clearly see it's a private method. $pNum is being randomly generated somewhere else.
3
u/Bit5keptical Sep 03 '21
Its pseudorandom.
3
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Sep 03 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!