当前位置: 首页>>代码示例>>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;未经允许,请勿转载。