Source for file RandomElements.class.php
Documentation is available at RandomElements.class.php
* RandomElements.class.php
* File with the class used to generate random elements (users, URL's ...)
* @author José Manuel Ciges Regueiro <jmanuel@ciges.net>, Web page {@link http://www.ciges.net}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPLv3
* @package InternetAccessLog
* This class is used to generate random elements (users, IP's and URL's) to make tests (populate tables in MySQL or collections in MongoDB)
* @package InternetAccessLog
* List of possible HTTP Methods
private $listOfHTTPMethods = array("CONNECT", "GET", "HEAD", "MKCOL", "OPTIONS", "POST", "PROPFIN", "PUT");
* List of possible FTP Methods
private $listOfFTPMethods = array("NOOP", "PWD", "RETR", "SIZE", "STOR", "TYPE", "USER");
* List of possible protocolos
private $listOfProtocols = array("http", "tunn");
* List of possible first level internet domains
private $listOfInternetDomains = array(".ar", ".asia", ".biz", ".bo", ".cat", ".cl", ".co", ".cn", ".com", ".cr", ".do", ".ec", ".edu", ".es", ".eu", ".fm", ".fr", ".gov", ".gt", ".hn", ".info", ".int", ".jobs", ".lat", ".mil", ".mobi", ".museum", ".mx", ".ni", ".name", ".net", ".nl", ".org", ".pe", ".pro", ".py", ".ru", ".sv", ".tel", ".tk", ".travel", ".tv", ".ua", ".uy", ".ve", ".web", ".ws", ".xxx", "r", ".asia", ".biz", ".bo", ".cat", ".cl", ".co", ".cn", ".com", ".cr", ".do", ".ec", ".edu", ".es", ".eu", ".fm", ".fr", ".gov", ".gt", ".hn", ".info", ".int", ".jobs", ".lat", ".mil", ".mobi", ".museum", ".mx", ".ni", ".name", ".net", ".nl", ".org", ".pe", ".pro", ".py", ".ru", ".sv", ".tel", ".tk", ".travel", ".tv", ".ua", ".uy", ".ve", ".web", ".ws", ".xxx");
* List of possible return codes
private $listOfRetourCodes = array(200, 201, 207, 301, 304, 403, 404, 405, 500, 502);
* Returns a random user, composed of one letter and 6 numbers
$letter = "abcdefghijklmnopqrstuvwxyz";
* Returns a random IP (string with 4 numbers between 0 and 255). No check for validity is made
* Returns a semi random HTTP method (90% will be GET)
return $this->listOfHTTPMethods[array_rand($this->listOfHTTPMethods)];
* Returns a semi random HTTP method (90% will be RETR)
return $this->listOfFTPMethods[array_rand($this->listOfFTPMethods)];
* Returns a random protocol (90% will be http)
return $this->listOfProtocols[array_rand($this->listOfProtocols)];
* Returns a random Internet domain (a www followed by a random string ended by a valid internet
$domain = "www.". substr(implode($word), 0, $len). $this->listOfInternetDomains[mt_rand(0,count($this->listOfInternetDomains)- 1)];
* Returns a random string of the length demanded (10 characters by default)
* Returns a semirandom return code (90% are 200 return code)
return $this->listOfRetourCodes[array_rand($this->listOfRetourCodes)];
* Return a random size between 0 and 50K
* Return a random date between the two dates passes as parameters. Parameters and return value are English textual datetime descriptions 'Y-m-d H:i:s'
* @param string $mindate English textual datetime description 'Y-m-d H:i:s' of minimun date
* @param string $maxdate English textual datetime description 'Y-m-d H:i:s' of maximun date
return date('Y-m-d H:i:s', rand($min, $max));
|