/** * Displays the ngglegacy thumbnail gallery. * This method deprecates the use of the nggShowGallery() function. * @param stdClass|C_Displayed_Gallery|C_DataMapper_Model $displayed_gallery */ function index_action($displayed_gallery, $return = FALSE) { // Get the images to be displayed $current_page = (int) $this->param('nggpage', 1); if ($images = $displayed_gallery->get_included_entities()) { // Get the gallery storage component $storage = $this->object->get_registry()->get_utility('I_Gallery_Storage'); // Create parameter list for the view $params = $displayed_gallery->display_settings; $params['storage'] =& $storage; $params['images'] =& $images; $params['displayed_gallery_id'] = $displayed_gallery->id(); $params['current_page'] = $current_page; $params['effect_code'] = $this->object->get_effect_code($displayed_gallery); $params['anchor'] = 'ngg-slideshow-' . $displayed_gallery->id() . '-' . rand(1, getrandmax()) . $current_page; $gallery_width = $displayed_gallery->display_settings['gallery_width']; $gallery_height = $displayed_gallery->display_settings['gallery_height']; $params['aspect_ratio'] = $gallery_width / $gallery_height; $params['placeholder'] = $this->object->get_static_url('photocrati-nextgen_basic_gallery#slideshow/placeholder.gif'); // Are we to generate a thumbnail link? if ($displayed_gallery->display_settings['show_thumbnail_link']) { $params['thumbnail_link'] = $this->object->get_url_for_alternate_display_type($displayed_gallery, NGG_BASIC_THUMBNAILS); } $params = $this->object->prepare_display_parameters($displayed_gallery, $params); $retval = $this->object->render_partial('photocrati-nextgen_basic_gallery#slideshow/index', $params, $return); } else { $retval = $this->object->render_partial('photocrati-nextgen_gallery_display#no_images_found', array(), $return); } return $retval; }
/** * Constructor * * Instantiate the CSRF form element object. * * @param string $name * @param string $value * @param int $expire * @param string $indent * @return \Pop\Form\Element\Csrf */ public function __construct($name, $value = null, $expire = 300, $indent = null) { // Start a session. if (session_id() == '') { session_start(); } // If token does not exist, create one if (!isset($_SESSION['pop_csrf'])) { $this->token = array('value' => sha1(rand(10000, getrandmax()) . $value), 'expire' => (int) $expire, 'start' => time()); $_SESSION['pop_csrf'] = serialize($this->token); // Else, retrieve existing token } else { $this->token = unserialize($_SESSION['pop_csrf']); // Check to see if the token has expired if ($this->token['expire'] > 0) { if ($this->token['expire'] + $this->token['start'] < time()) { $this->token = array('value' => sha1(rand(10000, getrandmax()) . $value), 'expire' => (int) $expire, 'start' => time()); $_SESSION['pop_csrf'] = serialize($this->token); } } } parent::__construct('hidden', $name, $this->token['value'], null, $indent); $this->setRequired(true); $this->setValidator(); }
public function testHighLoad() { $nItems = array(); $max = (double) getrandmax(); for ($i = 0; $i < self::MAX; $i++) { $nItems[] = $this->buildMarker('marker_' . $i, 58 + $this->getRandomOffset($max), 24 + $this->getRandomOffset($max)); } // $start = microtime(true); // $clustered = $this->c->clusterOriginal($nItems, 100, 11); // $stop = microtime(true); // $this->assertTrue($stop - $start < 21); // printf("Cluster end in %f seconds\n", $stop - $start); // $count = count($clustered); // $this->assertTrue($count < self::MAX && $count > 1); // unset($count); // unset($clustered); // unset($start); // unset($stop); $start = microtime(true); $clustered = $this->c->cluster($nItems, 100, 11); $stop = microtime(true); $this->assertTrue($stop - $start < 21); $count = count($clustered); $this->assertTrue($count < self::MAX && $count > 1); printf("Cluster end in %f seconds\n", $stop - $start); var_dump($clustered); }
function randomPastelColor() { $red = (double) rand() / (double) getrandmax() * 150 + 105; $green = (double) rand() / (double) getrandmax() * 150 + 105; $blue = (double) rand() / (double) getrandmax() * 150 + 105; return "#" . dechex($red) . dechex($green) . dechex($blue); }
/** * @todo keep a documentation record of globals */ protected static function initializeGlobals() { //initialize globals static::$globals = new \stdClass(); static::$globals->{'rand-integer'} = function ($max = null) { if ($max === null) { $max = getrandmax(); } else { $max = intval($max); } return rand(0, $max); }; static::$globals->{'rand-string'} = [Util::class, 'readableRandomString']; static::$globals->{'rand-hash'} = function () { return sha1(rand() . mt_rand() . rand()); }; static::$globals->{'rand-boolean'} = function () { return (bool) rand(0, 1); }; static::$globals->{'timestamp'} = function () { return time(); }; static::$globals->{'microtime'} = function ($get_as_float = false) { return microtime((bool) $get_as_float); }; }
function test() { // Tests sccp into a binop // { phc-option: -O1 --dump=codegen } // Check propagation into bin_ops // { phc-regex-output: /5 </ } $const = 5; if ($const < rand()) { print `echo 5`; // side-effecting } else { print `echo 5`; // side-effecting } // Check propagation into unary ops // { phc-regex-output: !/\$const2/ } $const2 = 6; if (!$const2 && rand()) { print `echo 5`; // side-effecting } else { print `echo 5`; // side-effecting } // Check that dead vars that go through PHIs are removed // { phc-regex-output: !/\$const3/ } // Check that getrandmax is optimized out // { phc-regex-output: !/getrandmax/ } while ($argv[3] > getrandmax() / 2) { $const3 = "string"; print `echo {$const3}`; } // Check we've removed all the !s // { phc-regex-output: !/!/ } }
function beforeSendRequest(Event $event) { $secondsPerConnection = 1 / $this->connectionsPerSecond; $secondsPerConnection *= 2 * rand() / getrandmax(); // Distribute parallel connections usleep($secondsPerConnection * 1000000); }
public function random($min = 0, $max = null) { if ($max === null) { $max = getrandmax(); } return rand($min, $max); }
public static function buildFile($file, $dir, $name) { $doc_root = $_SERVER["DOCUMENT_ROOT"]; $num = getrandmax(); $date = date("Y-m-d H:i:s"); $new_name = md5($num . $name . $date); $file->move($doc_root . "/photos/" . $dir, $new_name . "." . $extFile); }
function enterObject() { $this->setValue(substr(md5(microtime() . rand(1000, getrandmax())), 0, 6)); $this->params['value_pool']['email'][$this->getName()] = stripslashes($this->getValue()); if ($this->getElement(2) != 'no_db') { $this->params['value_pool']['sql'][$this->getName()] = $this->getValue(); } }
public function next($context = null) { if (rand() / getrandmax() < $e) { return $this->explore(); } else { return $this->exploit(); } }
public function getRowGenerationOptions($generator, $postdata, $colNum, $numCols) { if (empty($postdata["dtOptionMean_{$colNum}"]) && $postdata["dtOptionMean_{$colNum}"] !== "0" || empty($postdata["dtOptionSigma_{$colNum}"]) && $postdata["dtOptionSigma_{$colNum}"] !== "0") { return false; } $this->randMax = (double) getrandmax(); return array("mean" => $postdata["dtOptionMean_{$colNum}"], "stddev" => $postdata["dtOptionSigma_{$colNum}"]); }
function initWeights() { for ($i = 0; $i < $this->numHidden; $i++) { $this->weightsHO[$i] = (rand() / getrandmax() - 0.5) / 2; for ($j = 0; $j < $this->numInputs; $j++) { $this->weightsIH[$j][$i] = (rand() / getrandmax() - 0.5) / 5; } } }
/** * Create a random string. * DO NOT USE THIS FOR PASSWORDS AND SUCH! * @param int $length - Length of the string. */ function random_string($length = 32) { $count = ceil($length / 40); $string = ''; for ($i = 0; $i < $count; $i++) { $string .= sha1(rand(0, getrandmax()) . $string); } return substr($string, 0, $length); }
public function getInput($value = '', $name = '') { $name = $name ? $name : $this->getName(); if ($s = $this->getStatic()) { $r = rand(0, getrandmax()); $s = $s . '<nobr> <input name="' . $name . '_delete" type="checkbox" id="' . $r . '"><label for="' . $r . '" style="position:relative; top:-2px;">удалить</label></nobr><br>'; } return '<input type="hidden" name="' . $name . '_oldValue" value="' . $this->dbValue . '">' . $s . '<input type="file" name="' . $name . '" size="49" style="width:100%">'; }
protected function _versionHash() { $hash = $this->loadCache(self::FUZE_VALUE_CACHE_KEY); if ($hash === false) { $hash = sha1(rand(1, getrandmax())); $this->saveCache(self::FUZE_VALUE_CACHE_KEY, $hash); } return $hash; }
/** * Generate a random number/integer * @param int $min * @param int $max * @return int */ static function number($min = 0, $max = null) { mt_srand(); if (is_null($max)) { $max = getrandmax(); } $number = mt_rand($min, $max); return $number; }
/** * @throws FileException */ public function upload() { if ($this->file instanceof File) { $name = sha1($this->file->getClientOriginalName() . uniqid() . getrandmax()) . '.' . $this->file->guessExtension(); $this->file->move($this->getWeb() . $this->folder, $name); $this->file = $name; } else { throw new FileException('It must be a Symfony\\Component\\HttpFoundation\\File\\File instance'); } }
/** * Fill the matrix with random values * To reproduce, use srand first * * @param int $row The number of rows * @param int $col The number of columns * @param Number $min The minimum value * @param Number $max The maximum value */ public function rand_fill($row, $col, $min = 0, $max = 1) { $maxrand = getrandmax(); for ($i = 0; $i < $row; $i++) { $this->data[$i] = array(); for ($j = 0; $j < $col; $j++) { $this->data[$i][$j] = rand(0, $maxrand) / $maxrand * ($max - $min) + $min; } } }
public function displayValues($content_node, $transient_options, $action) { if (!($mainNode = $this->template->appendFileByNode('form_builder_menu.html', 'div', $content_node)) instanceof DOMNode) { I2CE::raiseError("no template form_builder_menu.html"); return false; } if (($nameNode = $this->template->getElementByName('name', 0, $mainNode)) instanceof DOMNode) { $all_forms = $this->storage->getKeys(); //these are all the classes, not just the ones with a registered handler $this->template->setClassValue($nameNode, 'validate_data', array('notinlist' => $all_forms), '%'); } if (($storageNode = $this->template->getElementByName('storage', 0, $mainNode)) instanceof DOMNode) { $storeid = "class_" . rand(0, getrandmax()); $storageNode->setAttribute('id', $storeid); $storages = I2CE::getConfig()->getAsArray('/modules/form-builder/storage_handlers'); foreach ($storages as $storage => $data) { if (!is_array($data) || !array_key_exists('swiss', $data) || !is_scalar($swiss = $data['swiss']) || !$swiss) { continue; } $attrs = array('value' => $storage); if (array_key_exists('description', $data)) { $attrs['title'] = $data['description']; } $storageNode->appendChild($this->template->createElement('option', $attrs, $storage)); } } if (($classNode = $this->template->getElementByName('class', 0, $mainNode)) instanceof DOMNode) { $classes = I2CE::getConfig()->getKeys("/modules/forms/formClasses"); $def_storage = array(); foreach ($classes as $class) { if ($class == 'I2CE_List' || is_subclass_of($class, 'I2CE_List')) { $def_storage[$class] = 'magicdata'; } else { $def_storage[$class] = 'entry'; } $attrs = array('value' => $class); $classNode->appendChild($this->template->createElement('option', $attrs, $class)); } $js = 'var storages = ' . json_encode($def_storage) . '; var storage=storages[this.value]; var storageNode = $("' . $storeid . '"); if (storageNode) { storageNode.set("value",storage);}'; $classNode->setAttribute('onChange', $js); } $this->renameInputs(array('class', 'name', 'display', 'storage'), $mainNode); if (($append_node = $this->template->getElementById('forms', $mainNode)) instanceof DOMNode) { $forms = $this->storage->getKeys(); foreach ($forms as $form) { if (!($swissChild = $this->getChild($form)) instanceof I2CE_Swiss_Form || !($formNode = $this->template->appendFileByNode('form_builder_each.html', 'li', $append_node))) { continue; } $this->template->setDisplayDataImmediate("form", $form, $formNode); $this->template->setDisplayDataImmediate("form_edit_link", $this->getURLRoot('edit') . $this->path . '/' . $form, $formNode); $this->template->setDisplayDataImmediate("form_delete_link", $this->getURLRoot('delete') . $this->path . '/' . $form, $formNode); } } return true; }
/** * Return the maxium random number * * @access public * @return double */ public function max($value = null) { if ($value === null && $this->max === null) { $max = getrandmax(); } elseif ($value === null) { $max = $this->max; } else { $max = $this->max = $value; } return $max; }
static function makeRandomNumber($numDigits, $hasPadding) { $maxValue = pow(10, $numDigits) - 1; if ($maxValue > getrandmax()) { $maxValue = getrandmax(); } $value = rand(0, $maxValue); $format = '%' . ($hasPadding ? '0' : '') . $numDigits . 'd'; return trim(sprintf($format, $value)); // trim needed, when $hasPadding == false }
public function testRowFilterSortDescending() { $rows = Utils::makeRows(); $statement = new SortingFilterStatement(Utils::INT_FIELD_NAME, FilterStatement::COND_SORT_DESC, null, null); $rows = $statement->applyToRows($rows); $lastNumber = getrandmax() + 1; foreach ($rows as $row) { $thisNumber = $row->getWritableBearer()->getWritableByHandle(Utils::INT_FIELD_NAME)->getInitial(); $this->assertLessThanOrEqual($lastNumber, $thisNumber); $lastNumber = $thisNumber; } }
public static function getUniqFileName($file, $dir) { $dir = trim('/', $dir); if (mb_strpos($dir, $_SERVER['DOCUMENT_ROOT']) === false) { $dir = $_SERVER['DOCUMENT_ROOT'] . $dir . '/'; } $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION)); $name = md5(rand(0, getrandmax()) . uniqid("", true) . uniqid("", true) . $file) . '.' . $ext; if (file_exists($dir . $name)) { self::getUniqFileName($name, $dir); } return $name; }
/** * @param int $vectorLength The number of input signals * @param float $bias Bias factor * @param float $learningRate The learning rate 0 < x <= 1 * * @throws \InvalidArgumentException */ public function __construct($vectorLength, $bias = 0.0, $learningRate = 0.5) { if ($vectorLength < 1) { throw new \InvalidArgumentException(); } elseif ($learningRate <= 0 || $learningRate > 1) { throw new \InvalidArgumentException(); } $this->vectorLength = $vectorLength; $this->bias = $bias; $this->learningRate = $learningRate; for ($i = 0; $i < $this->vectorLength; $i++) { $this->weightVector[$i] = rand() / getrandmax() * 2 - 1; } }
function generateRandomId() { mt_srand((double) microtime() * 1000000); $randIdMin = 0; $randIdMax = getrandmax(); while (true) { $id = (int) mt_rand($randIdMin, $randIdMax); $this->db->setQuery("SELECT id FROM #__user WHERE id = {$id}"); $ret = $this->db->loadResult(); if (is_null($ret)) { return $id; } } }
/** * Generate a random float * * @return float */ private function generateRandomRange() { $min = 0; $max = getrandmax(); if (isset($this->config['range'])) { if (isset($this->config['range']['min'])) { $min = $this->config['range']['min']; } if (isset($this->config['range']['max'])) { $max = $this->config['range']['max']; } } return mt_rand($min, $max); }
/** * */ public function testRandom() { // WHEN $actual1 = $this->object->rand(1, 2); $actual2 = $this->object->rand(1); $actual3 = $this->object->rand(); // THEN $this->assertGreaterThanOrEqual(1, $actual1); $this->assertLessThanOrEqual(2, $actual1); $this->assertGreaterThanOrEqual(1, $actual2); $this->assertLessThanOrEqual(getrandmax(), $actual2); $this->assertGreaterThanOrEqual(0, $actual3); $this->assertLessThanOrEqual(getrandmax(), $actual3); }
/** * Get the strength of the site secret * * @return string "strong", "moderate", or "weak" * @access private */ function getStrength() { $secret = get_site_secret(); if ($secret[0] !== 'z') { $rand_max = getrandmax(); if ($rand_max < pow(2, 16)) { return 'weak'; } if ($rand_max < pow(2, 32)) { return 'moderate'; } } return 'strong'; }
public function getInput($value = '', $name = '', $search = false) { global $PRJ_REF; if ($search) { return '<input type="text" id="' . ($name ? $name : $this->getName()) . '" name="' . ($name ? $name : $this->getName()) . '" style="width:100%" value="' . htmlspecialchars($value) . '">'; } $value = !$value ? $this->dbValue : $value; $name = !$name ? $this->getName() : $name; $r_ = rand(0, getrandmax()); $field = '<input type="checkbox" id="' . $r_ . '" checked onClick="controlEditor(this, \'' . $name . '\')"><label for="' . $r_ . '" style="position:relative; top:-2px;">Редактор</label>'; $field .= '<textarea class="mceEditor" id="' . $name . '" name="' . $name . '" rows="6" cols="40" style="height:300px;width:100%"> ' . htmlspecialchars($value) . '</textarea>'; return $field; }