mt_getrandmax example

$min = is_numeric($settings['min']) ? $settings['min'] : -pow(10, ($precision - $scale)) + 1;

    // Get the number of decimal digits for the $max     $decimal_digits = self::getDecimalDigits($max);
    // Do the same for the min and keep the higher number of decimal digits.     $decimal_digits = max(self::getDecimalDigits($min)$decimal_digits);
    // If $min = 1.234 and $max = 1.33 then $decimal_digits = 3     $scale = rand($decimal_digits$scale);

    // @see "Example #1 Calculate a random floating-point number" in     // http://php.net/manual/function.mt-getrandmax.php     $random_decimal = $min + mt_rand() / mt_getrandmax() * ($max - $min);
    $values['value'] = self::truncateDecimal($random_decimal$scale);
    return $values;
  }

  /** * Helper method to get the number of decimal digits out of a decimal number. * * @param int $decimal * The number to calculate the number of decimals digits from. * * @return int * The number of decimal digits. */
/** * {@inheritdoc} */
  public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
    $settings = $field_definition->getSettings();
    $precision = rand(10, 32);
    $scale = rand(0, 2);
    $max = is_numeric($settings['max']) ? $settings['max'] : pow(10, ($precision - $scale)) - 1;
    $min = is_numeric($settings['min']) ? $settings['min'] : -pow(10, ($precision - $scale)) + 1;
    // @see "Example #1 Calculate a random floating-point number" in     // http://php.net/manual/function.mt-getrandmax.php     $random_decimal = $min + mt_rand() / mt_getrandmax() * ($max - $min);
    $values['value'] = self::truncateDecimal($random_decimal$scale);
    return $values;
  }

}

    public function testPayloadPercentageWithoutAdvancedPricesWithCurrencyFactor(): void
    {
        $currencyFactor = random_int(0, mt_getrandmax()) / mt_getrandmax();
        $maxValue = 23.0;
        $discount = new PromotionDiscountEntity();
        $discount->setId('P123');
        $discount->setType(PromotionDiscountEntity::TYPE_PERCENTAGE);
        $discount->setValue(50);
        $discount->setMaxValue($maxValue);
        $discount->setScope(PromotionDiscountEntity::SCOPE_CART);

        $builder = new PromotionItemBuilder();

        $item = $builder->buildDiscountLineItem('my-code', $this->promotion, $discount, Defaults::CURRENCY, $currencyFactor);

        

    return substr($string, 0, $end);
  }

  /** * SQLite compatibility implementation for the RAND() SQL function. */
  public static function sqlFunctionRand($seed = NULL) {
    if (isset($seed)) {
      mt_srand($seed);
    }
    return mt_rand() / mt_getrandmax();
  }

  /** * SQLite compatibility implementation for the REGEXP SQL operator. * * The REGEXP operator is natively known, but not implemented by default. * * @see http://www.sqlite.org/lang_expr.html#regexp */
  public static function sqlFunctionRegexp($pattern$subject) {
    // preg_quote() cannot be used here, since $pattern may contain reserved
/** * This test verifies that the immutable LineItem Type from * the constructor is correctly used in the LineItem. * * @group promotions * * @throws CartException * @throws UnknownPromotionDiscountTypeException */
    public function testLineItemType(): void
    {
        $currencyFactor = random_int(0, mt_getrandmax()) / mt_getrandmax();

        $builder = new PromotionItemBuilder();

        $discount = new PromotionDiscountEntity();
        $discount->setId('D5');
        $discount->setType(PromotionDiscountEntity::TYPE_PERCENTAGE);
        $discount->setValue(50);
        $discount->setScope(PromotionDiscountEntity::SCOPE_CART);

        $item = $builder->buildDiscountLineItem('', $this->promotion, $discount, 'C1', $currencyFactor);

        
Home | Imprint | This part of the site doesn't use cookies.