WebsiteBaker Logo
  • *
  • Templates
  • Help
  • Add-ons
  • Download
  • Home
*
Welcome, Guest. Please login or register.

Login with username, password and session length
 

News


WebsiteBaker 2.13.6 is now available!


Will it continue with WB? It goes on! | Geht es mit WB weiter? Es geht weiter!
https://forum.websitebaker.org/index.php/topic,32340.msg226702.html#msg226702


The forum email address board@websitebaker.org is working again
https://forum.websitebaker.org/index.php/topic,32358.0.html


R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WB
https://forum.websitebaker.org/index.php/topic,32355.0.html


* Support WebsiteBaker

Your donations will help to:

  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!

You can donate by clicking on the button below.


  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • General Community »
  • Off-Topic »
  • Pop Quiz - Separate the serious coders from the cut-and-paste script kiddies.
  • Print
Pages: [1]   Go Down

Author Topic: Pop Quiz - Separate the serious coders from the cut-and-paste script kiddies.  (Read 6142 times)

NorHei

  • Guest
Pop Quiz - Separate the serious coders from the cut-and-paste script kiddies.
« on: July 08, 2012, 11:25:46 AM »
Here's a little test to separate the serious coders from the cut-and-paste script kiddies. Given the need to generate an arbitrarily long string consisting of random alpha-numeric characters, which solution is best?


http://zaemis.blogspot.de/2009/10/pop-quiz.html


Have fun  :lol:
Logged

Offline pcwacht

  • Posts: 2923
  • Gender: Male
    • Dutch ICT info
Re: Pop Quiz - Separate the serious coders from the cut-and-paste script kiddies.
« Reply #1 on: July 08, 2012, 01:39:25 PM »
lol

Since I learned programming way back around 1980-ish then a good programmer use as less as and to make it as fast as possible.

Nowadays that has changed to make it reuasable and more readable.
Even creating loads of extra lines.

My solution would be somtehing like:
Code: [Select]
function randomString($len,$chars) {
    $rndMax = strlen($chars) - 1;
    $str = "";
    while ($len-- != 0) {
        $str .= $chars[rand(0, $rndMax)];
    }
    return $str;
}

$chars  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" .
              "abcdefghijklmnopqrstuvwxyz" .
              "0123456789";
$str = randomString(8,$chars);
echo "$str\n";

Maybe adding some checks to set defaults.

Oh and if I neede this once I think I could do without the function as well ;)


John
« Last Edit: July 08, 2012, 01:43:02 PM by pcwacht »
Logged
http://www.ictwacht.nl = Dutch ICT info
http://www.pcwacht.nl = My first
both still work in progress, since years.....

NorHei

  • Guest
Re: Pop Quiz - Separate the serious coders from the cut-and-paste script kiddies.
« Reply #2 on: July 08, 2012, 06:09:50 PM »
or maybe use :
Code: [Select]
include ("filename.php");

 :lol:


Wo wir schon mal beim kürzen sind:
Code: [Select]
function randomString($len,$char) {
     for ($p = 0; $p < $len; $p++) $string .= $char[rand(0, strlen($char)-1)];
    return $string;
}
Logged

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • General Community »
  • Off-Topic »
  • Pop Quiz - Separate the serious coders from the cut-and-paste script kiddies.
 

  • SMF 2.0.19 | SMF © 2017, Simple Machines
  • XHTML
  • RSS
  • WAP2