当前位置: 首页>>代码示例>>PHP>>正文


PHP Random::getRandomNumber方法代码示例

本文整理汇总了PHP中Magento\Framework\Math\Random::getRandomNumber方法的典型用法代码示例。如果您正苦于以下问题:PHP Random::getRandomNumber方法的具体用法?PHP Random::getRandomNumber怎么用?PHP Random::getRandomNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Math\Random的用法示例。


在下文中一共展示了Random::getRandomNumber方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _randomSize

 /**
  * Override function to generate less curly captcha that will not cut off
  *
  * @see \Zend_Captcha_Image::_randomSize()
  * @return int
  */
 protected function _randomSize()
 {
     return \Magento\Framework\Math\Random::getRandomNumber(280, 300) / 100;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:10,代码来源:DefaultModel.php

示例2: isCleanupProbability

 /**
  * Calculate cleanup possibility for data with lifetime property
  *
  * @return bool
  */
 public function isCleanupProbability()
 {
     // Safe get cleanup probability value from system configuration
     $configValue = (int) $this->_scopeConfig->getValue(self::XML_PATH_CLEANUP_PROBABILITY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     return $configValue > 0 ? 1 == \Magento\Framework\Math\Random::getRandomNumber(1, $configValue) : false;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:11,代码来源:Data.php

示例3: createPdfPageFromImageString

 /**
  * Create \Zend_Pdf_Page instance with image from $imageString. Supports JPEG, PNG, GIF, WBMP, and GD2 formats.
  *
  * @param string $imageString
  * @return \Zend_Pdf_Page|false
  */
 public function createPdfPageFromImageString($imageString)
 {
     /** @var \Magento\Framework\Filesystem\Directory\Write $directory */
     $directory = $this->filesystem->getDirectoryWrite(DirectoryList::TMP);
     $directory->create();
     $image = @imagecreatefromstring($imageString);
     if (!$image) {
         return false;
     }
     $xSize = imagesx($image);
     $ySize = imagesy($image);
     $page = new \Zend_Pdf_Page($xSize, $ySize);
     imageinterlace($image, 0);
     $tmpFileName = $directory->getAbsolutePath('shipping_labels_' . uniqid(\Magento\Framework\Math\Random::getRandomNumber()) . time() . '.png');
     imagepng($image, $tmpFileName);
     $pdfImage = \Zend_Pdf_Image::imageWithPath($tmpFileName);
     $page->drawImage($pdfImage, 0, 0, $xSize, $ySize);
     $directory->delete($directory->getRelativePath($tmpFileName));
     return $page;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:26,代码来源:LabelGenerator.php

示例4: _beforeSave

 /**
  * Processing object before save data
  *
  * @return $this
  */
 protected function _beforeSave()
 {
     parent::_beforeSave();
     $this->_checkState();
     if (!$this->getId()) {
         $store = $this->getStore();
         $name = array($store->getWebsite()->getName(), $store->getGroup()->getName(), $store->getName());
         $this->setStoreName(implode("\n", $name));
     }
     if (!$this->getIncrementId()) {
         $incrementId = $this->_eavConfig->getEntityType('order')->fetchNewIncrementId($this->getStoreId());
         $this->setIncrementId($incrementId);
     }
     /**
      * Process items dependency for new order
      */
     if (!$this->getId()) {
         $itemsCount = 0;
         foreach ($this->getAllItems() as $item) {
             $parent = $item->getQuoteParentItemId();
             if ($parent && !$item->getParentItem()) {
                 $item->setParentItem($this->getItemByQuoteItemId($parent));
             } elseif (!$parent) {
                 $itemsCount++;
             }
         }
         // Set items count
         $this->setTotalItemCount($itemsCount);
     }
     /** TODO refactor getCustomer usage after MAGETWO-20182 and MAGETWO-20258 are done */
     $isNewCustomer = !$this->getCustomerId() || $this->getCustomerId() === true;
     if ($isNewCustomer && $this->getCustomer()) {
         $this->setCustomerId($this->getCustomer()->getId());
     }
     if ($this->hasBillingAddressId() && $this->getBillingAddressId() === null) {
         $this->unsBillingAddressId();
     }
     if ($this->hasShippingAddressId() && $this->getShippingAddressId() === null) {
         $this->unsShippingAddressId();
     }
     $this->setData('protect_code', substr(md5(uniqid(\Magento\Framework\Math\Random::getRandomNumber(), true) . ':' . microtime(true)), 5, 6));
     return $this;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:48,代码来源:Order.php

示例5: _beforeSave

 /**
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if (!$object->getId()) {
         /** @var \Magento\Store\Model\Store $store */
         $store = $object->getStore();
         $name = [$store->getWebsite()->getName(), $store->getGroup()->getName(), $store->getName()];
         $object->setStoreName(implode(PHP_EOL, $name));
         $object->setTotalItemCount($this->calculateItems($object));
     }
     $object->setData('protect_code', substr(md5(uniqid(Random::getRandomNumber(), true) . ':' . microtime(true)), 5, 6));
     $isNewCustomer = !$object->getCustomerId() || $object->getCustomerId() === true;
     if ($isNewCustomer && $object->getCustomer()) {
         $object->setCustomerId($object->getCustomer()->getId());
     }
     return parent::_beforeSave($object);
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:20,代码来源:Order.php

示例6: generateCode

 /**
  * Generate coupon code
  *
  * @return string
  */
 public function generateCode()
 {
     $format = $this->getFormat();
     if (!$format) {
         $format = \Magento\SalesRule\Helper\Coupon::COUPON_FORMAT_ALPHANUMERIC;
     }
     $length = max(1, (int) $this->getLength());
     $split = max(0, (int) $this->getDash());
     $suffix = $this->getSuffix();
     $prefix = $this->getPrefix();
     $splitChar = $this->getDelimiter();
     $charset = $this->_salesRuleCoupon->getCharset($format);
     $code = '';
     $charsetSize = count($charset);
     for ($i = 0; $i < $length; $i++) {
         $char = $charset[\Magento\Framework\Math\Random::getRandomNumber(0, $charsetSize - 1)];
         if ($split > 0 && $i % $split == 0 && $i != 0) {
             $char = $splitChar . $char;
         }
         $code .= $char;
     }
     $code = $prefix . $code . $suffix;
     return $code;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:29,代码来源:Massgenerator.php

示例7: fetchAndSave

 /**
  * Goes to specified host/path and fetches reports from there.
  * Save reports to database.
  *
  * @param \Magento\Framework\Filesystem\Io\Sftp $connection
  * @return int Number of report rows that were fetched and saved successfully
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function fetchAndSave(\Magento\Framework\Filesystem\Io\Sftp $connection)
 {
     $fetched = 0;
     $listing = $this->_filterReportsList($connection->rawls());
     foreach ($listing as $filename => $attributes) {
         $localCsv = 'PayPal_STL_' . uniqid(\Magento\Framework\Math\Random::getRandomNumber()) . time() . '.csv';
         if ($connection->read($filename, $this->_tmpDirectory->getAbsolutePath($localCsv))) {
             if (!$this->_tmpDirectory->isWritable($localCsv)) {
                 throw new \Magento\Framework\Exception\LocalizedException(__('We cannot create a target file for reading reports.'));
             }
             $encoded = $this->_tmpDirectory->readFile($localCsv);
             $csvFormat = 'new';
             $fileEncoding = mb_detect_encoding($encoded);
             if (self::FILES_OUT_CHARSET != $fileEncoding) {
                 $decoded = @iconv($fileEncoding, self::FILES_OUT_CHARSET . '//IGNORE', $encoded);
                 $this->_tmpDirectory->writeFile($localCsv, $decoded);
                 $csvFormat = 'old';
             }
             // Set last modified date, this value will be overwritten during parsing
             if (isset($attributes['mtime'])) {
                 $lastModified = new \DateTime($attributes['mtime']);
                 $this->setReportLastModified($lastModified->format('Y-m-d H:i:s'));
             }
             $this->setReportDate($this->_fileNameToDate($filename))->setFilename($filename)->parseCsv($localCsv, $csvFormat);
             if ($this->getAccountId()) {
                 $this->save();
             }
             if ($this->_dataSaveAllowed) {
                 $fetched += count($this->_rows);
             }
             // clean object and remove parsed file
             $this->unsetData();
             $this->_tmpDirectory->delete($localCsv);
         }
     }
     return $fetched;
 }
开发者ID:nja78,项目名称:magento2,代码行数:45,代码来源:Settlement.php

示例8: testGetRandomNumber

 /**
  * @param $min
  * @param $max
  *
  * @dataProvider testGetRandomNumberProvider
  */
 public function testGetRandomNumber($min, $max)
 {
     $number = \Magento\Framework\Math\Random::getRandomNumber($min, $max);
     $this->assertLessThanOrEqual($max, $number);
     $this->assertGreaterThanOrEqual($min, $number);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:12,代码来源:RandomTest.php

示例9: randomSequence

 /**
  * Returns string of random chars
  *
  * @param int $length
  * @return string
  */
 public function randomSequence($length = 32)
 {
     $id = '';
     $par = [];
     $char = array_merge(range('a', 'z'), range(0, 9));
     $charLen = count($char) - 1;
     for ($i = 0; $i < $length; $i++) {
         $disc = \Magento\Framework\Math\Random::getRandomNumber(0, $charLen);
         $par[$i] = $char[$disc];
         $id = $id . $char[$disc];
     }
     return $id;
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:19,代码来源:Subscriber.php

示例10: generateUniqueIdPath

 /**
  * Return unique string based on the time in microseconds.
  *
  * @return string
  */
 public function generateUniqueIdPath()
 {
     return str_replace('.', '_', uniqid(\Magento\Framework\Math\Random::getRandomNumber(), true));
 }
开发者ID:aiesh,项目名称:magento2,代码行数:9,代码来源:Url.php


注:本文中的Magento\Framework\Math\Random::getRandomNumber方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。