當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Generator::randomFloat方法代碼示例

本文整理匯總了PHP中Faker\Generator::randomFloat方法的典型用法代碼示例。如果您正苦於以下問題:PHP Generator::randomFloat方法的具體用法?PHP Generator::randomFloat怎麽用?PHP Generator::randomFloat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Faker\Generator的用法示例。


在下文中一共展示了Generator::randomFloat方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: generateNumberData

 /**
  * Generate number data
  *
  * @param AbstractAttribute attribute
  *
  * @return string
  */
 protected function generateNumberData(AbstractAttribute $attribute)
 {
     $min = $attribute->getNumberMin() != null ? $attribute->getNumberMin() : self::DEFAULT_NUMBER_MIN;
     $max = $attribute->getNumberMax() != null ? $attribute->getNumberMax() : self::DEFAULT_NUMBER_MAX;
     $decimals = $attribute->isDecimalsAllowed() ? self::DEFAULT_NB_DECIMALS : 0;
     $number = $this->faker->randomFloat($decimals, $min, $max);
     return (string) $number;
 }
開發者ID:norfil,項目名稱:DataGeneratorBundle,代碼行數:15,代碼來源:ProductGenerator.php

示例2: __construct

 /**
  * @param FactoryInterface $taxRateFactory
  * @param RepositoryInterface $zoneRepository
  * @param RepositoryInterface $taxCategoryRepository
  */
 public function __construct(FactoryInterface $taxRateFactory, RepositoryInterface $zoneRepository, RepositoryInterface $taxCategoryRepository)
 {
     $this->taxRateFactory = $taxRateFactory;
     $this->faker = \Faker\Factory::create();
     $this->optionsResolver = (new OptionsResolver())->setDefault('name', function (Options $options) {
         return $this->faker->words(3, true);
     })->setDefault('code', function (Options $options) {
         return StringInflector::nameToCode($options['name']);
     })->setDefault('amount', function (Options $options) {
         return $this->faker->randomFloat(2, 0, 1);
     })->setAllowedTypes('amount', 'float')->setDefault('included_in_price', function (Options $options) {
         return $this->faker->boolean();
     })->setAllowedTypes('included_in_price', 'bool')->setDefault('calculator', 'default')->setDefault('zone', LazyOption::randomOne($zoneRepository))->setAllowedTypes('zone', ['null', 'string', ZoneInterface::class])->setNormalizer('zone', LazyOption::findOneBy($zoneRepository, 'code'))->setDefault('tax_category', LazyOption::randomOne($taxCategoryRepository))->setAllowedTypes('tax_category', ['null', 'string', TaxCategoryInterface::class])->setNormalizer('tax_category', LazyOption::findOneBy($taxCategoryRepository, 'code'));
 }
開發者ID:okwinza,項目名稱:Sylius,代碼行數:19,代碼來源:TaxRateExampleFactory.php

示例3: generateValueData

 /**
  * Generate value content based on backend type
  *
  * @param AbstractAttribute $attribute
  * @param string            $key
  *
  * @return string
  */
 protected function generateValueData(AbstractAttribute $attribute, $key)
 {
     $data = "";
     if (isset($this->forcedValues[$attribute->getCode()])) {
         return $this->forcedValues[$attribute->getCode()];
     }
     switch ($attribute->getBackendType()) {
         case "varchar":
             $validationRule = $attribute->getValidationRule();
             switch ($validationRule) {
                 case 'url':
                     $data = $this->faker->url();
                     break;
                 default:
                     $data = $this->faker->sentence();
                     break;
             }
             break;
         case "text":
             $data = $this->faker->sentence();
             break;
         case "date":
             $data = $this->faker->dateTimeBetween($attribute->getDateMin(), $attribute->getDateMax());
             $data = $data->format('Y-m-d');
             break;
         case "metric":
         case "decimal":
         case "prices":
             if ($attribute->getBackendType() && preg_match('/-' . self::METRIC_UNIT . '$/', $key)) {
                 $data = $attribute->getDefaultMetricUnit();
             } else {
                 $min = $attribute->getNumberMin() != null ? $attribute->getNumberMin() : self::DEFAULT_NUMBER_MIN;
                 $max = $attribute->getNumberMax() != null ? $attribute->getNumberMax() : self::DEFAULT_NUMBER_MAX;
                 $decimals = $attribute->isDecimalsAllowed() ? self::DEFAULT_NB_DECIMALS : 0;
                 $data = $this->faker->randomFloat($decimals, $min, $max);
             }
             break;
         case "boolean":
             $data = $this->faker->boolean() ? "1" : "0";
             break;
         case "option":
         case "options":
             $options = [];
             foreach ($attribute->getOptions() as $option) {
                 $options[] = $option;
             }
             $option = $this->faker->randomElement($options);
             if (is_object($option)) {
                 $data = $option->getCode();
             }
             break;
         default:
             $data = '';
             break;
     }
     return (string) $data;
 }
開發者ID:norfil,項目名稱:DataGeneratorBundle,代碼行數:65,代碼來源:AssociationCsvGenerator.php

示例4: configureOptions

 /**
  * {@inheritdoc}
  */
 protected function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefault('code', function (Options $options) {
         return StringInflector::nameToCode($options['name']);
     })->setDefault('name', function (Options $options) {
         return $this->faker->words(3, true);
     })->setDefault('amount', function (Options $options) {
         return $this->faker->randomFloat(2, 0, 0.4);
     })->setAllowedTypes('amount', 'float')->setDefault('included_in_price', function (Options $options) {
         return $this->faker->boolean();
     })->setAllowedTypes('included_in_price', 'bool')->setDefault('calculator', 'default')->setDefault('zone', LazyOption::randomOne($this->zoneRepository))->setAllowedTypes('zone', ['null', 'string', ZoneInterface::class])->setNormalizer('zone', LazyOption::findOneBy($this->zoneRepository, 'code'))->setDefault('category', LazyOption::randomOne($this->taxCategoryRepository))->setAllowedTypes('category', ['null', 'string', TaxCategoryInterface::class])->setNormalizer('category', LazyOption::findOneBy($this->taxCategoryRepository, 'code'));
 }
開發者ID:sylius,項目名稱:sylius,代碼行數:15,代碼來源:TaxRateExampleFactory.php

示例5: fillItems

 private function fillItems(AcceptanceTester $I, $max = 2)
 {
     for ($i = 1; $i <= $max; $i++) {
         $row_selector = sprintf('table.invoice-table tbody tr:nth-child(%d) ', $i);
         $product_key = $this->faker->text(10);
         $description = $this->faker->text(80);
         $unit_cost = $this->faker->randomFloat(2, 0, 100);
         $quantity = $this->faker->randomDigitNotNull;
         $I->fillField($row_selector . '#product_key', $product_key);
         $I->fillField($row_selector . 'textarea', $description);
         $I->fillField($row_selector . 'td:nth-child(4) input', $unit_cost);
         $I->fillField($row_selector . 'td:nth-child(5) input', $quantity);
     }
 }
開發者ID:rafaelsisweb,項目名稱:invoice-ninja,代碼行數:14,代碼來源:InvoiceCest.php

示例6: seedSales

 /**
  * Only seed shops
  *
  * @param Shop $owner
  * @return void
  */
 private function seedSales($owner)
 {
     if (!$owner instanceof Shop) {
         return;
     }
     $products = $owner->products()->get();
     foreach ($products as $product) {
         if ($this->faker->boolean(50)) {
             continue;
         }
         /** @var Product $product */
         $product->sales()->save(factory(Sale::class)->make(['price' => $this->faker->randomFloat(2, 0.01, $product->price)]));
     }
 }
開發者ID:gez-studio,項目名稱:gez-mall,代碼行數:20,代碼來源:DevSeeder.php

示例7: getRandomValueForProductAttribute

 /**
  * @param ProductAttributeInterface $productAttribute
  *
  * @return mixed
  */
 private function getRandomValueForProductAttribute(ProductAttributeInterface $productAttribute)
 {
     switch ($productAttribute->getStorageType()) {
         case ProductAttributeValueInterface::STORAGE_BOOLEAN:
             return $this->faker->boolean;
         case ProductAttributeValueInterface::STORAGE_INTEGER:
             return $this->faker->numberBetween(0, 10000);
         case ProductAttributeValueInterface::STORAGE_FLOAT:
             return $this->faker->randomFloat(4, 0, 10000);
         case ProductAttributeValueInterface::STORAGE_TEXT:
             return $this->faker->sentence;
         case ProductAttributeValueInterface::STORAGE_DATE:
         case ProductAttributeValueInterface::STORAGE_DATETIME:
             return $this->faker->dateTimeThisCentury;
         default:
             throw new \BadMethodCallException();
     }
 }
開發者ID:loic425,項目名稱:Sylius,代碼行數:23,代碼來源:ProductExampleFactory.php

示例8: getRandomNumber

 /**
  * Get a random number, float or integer
  *
  * @param stdClass $schema
  * @param bool $float
  * @return float|int
  * @throws InvalidArgumentException
  */
 private function getRandomNumber(stdClass $schema, $float = false)
 {
     $multipleOf = $this->provider->getProperty($schema, 'multipleOf', $this->config->getMultipleOf());
     $maximum = $this->provider->getProperty($schema, 'maximum', $this->config->getMaximum());
     $minimum = $this->provider->getProperty($schema, 'minimum', $this->config->getMinimum());
     $exclusiveMaximum = $this->provider->getProperty($schema, 'exclusiveMaximum', false);
     $exclusiveMinimum = $this->provider->getProperty($schema, 'exclusiveMinimum', false);
     if (true === $exclusiveMaximum) {
         $maximum--;
     }
     if (true === $exclusiveMinimum) {
         $maximum++;
     }
     $decimals = $float ? $this->generator->numberBetween(0, 4) : 0;
     $modifier = 1 / pow(10, $decimals);
     $number = $float ? $this->generator->randomFloat($decimals, $minimum, $maximum) : $this->generator->numberBetween($minimum, $maximum);
     while ($number % $multipleOf !== 0) {
         $number += $modifier;
     }
     return $number;
 }
開發者ID:tebru,項目名稱:swagger-faker,代碼行數:29,代碼來源:SchemaGenerator.php

示例9: getRandomOrder

 /**
  * @return Order
  */
 protected function getRandomOrder()
 {
     $order = new Order();
     $order->setId($this->faker->numerify('####'))->setAmount($this->faker->randomFloat(2, 1, 100))->setCurrency('CHF')->setOrderText($this->faker->sentence(4));
     return $order;
 }
開發者ID:whatwedo,項目名稱:postfinance-e-payment,代碼行數:9,代碼來源:PostFinanceEPaymentTest.php


注:本文中的Faker\Generator::randomFloat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。