Skip to content

Commit 0ce8685

Browse files
ENGCOM-1511: [Forwardport] chore: use random_int() in some places #15128
- Merge Pull Request #15128 from mzeis/magento2:2.3-develop-PR-port-15017 - Merged commits: 1. 435d241
2 parents b16dfc6 + 435d241 commit 0ce8685

File tree

18 files changed

+20
-20
lines changed

18 files changed

+20
-20
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Massaction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function render(\Magento\Framework\DataObject $row)
6565
*/
6666
protected function _getCheckboxHtml($value, $checked)
6767
{
68-
$id = 'id_' . rand(0, 999);
68+
$id = 'id_' . random_int(0, 999);
6969
$html = '<label class="data-grid-checkbox-cell-inner" for="'. $id .'">';
7070
$html .= '<input type="checkbox" name="' . $this->getColumn()->getName() . '" ';
7171
$html .= 'id="' . $id . '" data-role="select-row"';

app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ protected function getTemporaryTreeIndexTableName()
597597
if (empty($this->tempTreeIndexTableName)) {
598598
$this->tempTreeIndexTableName = $this->connection->getTableName('temp_catalog_category_tree_index')
599599
. '_'
600-
. substr(md5(time() . rand(0, 999999999)), 0, 8);
600+
. substr(md5(time() . random_int(0, 999999999)), 0, 8);
601601
}
602602

603603
return $this->tempTreeIndexTableName;

app/code/Magento/SalesRule/Model/Coupon/Codegenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function generateCode()
3838
$length = $this->getActualLength();
3939
$code = '';
4040
for ($i = 0, $indexMax = strlen($alphabet) - 1; $i < $length; ++$i) {
41-
$code .= substr($alphabet, mt_rand(0, $indexMax), 1);
41+
$code .= substr($alphabet, random_int(0, $indexMax), 1);
4242
}
4343

4444
return $code;
@@ -54,7 +54,7 @@ protected function getActualLength()
5454
$lengthMin = $this->getLengthMin() ? $this->getLengthMin() : static::DEFAULT_LENGTH_MIN;
5555
$lengthMax = $this->getLengthMax() ? $this->getLengthMax() : static::DEFAULT_LENGTH_MAX;
5656

57-
return $this->getLength() ? $this->getLength() : mt_rand($lengthMin, $lengthMax);
57+
return $this->getLength() ? $this->getLength() : random_int($lengthMin, $lengthMax);
5858
}
5959

6060
/**

app/code/Magento/SalesRule/Model/Rule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ public function acquireCoupon($saveNewlyCreated = true, $saveAttemptCount = 10)
521521
$coupon->setCode(
522522
$couponCode . self::getCouponCodeGenerator()->getDelimiter() . sprintf(
523523
'%04u',
524-
rand(0, 9999)
524+
random_int(0, 9999)
525525
)
526526
);
527527
continue;

lib/internal/Magento/Framework/Encryption/Crypt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function __construct(
7575
$abc = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
7676
$initVector = '';
7777
for ($i = 0; $i < $initVectorSize; $i++) {
78-
$initVector .= $abc[rand(0, strlen($abc) - 1)];
78+
$initVector .= $abc[random_int(0, strlen($abc) - 1)];
7979
}
8080
} elseif (false === $initVector) {
8181
/* Set vector to zero bytes to not use it */

lib/internal/Magento/Framework/Setup/BackendFrontnameGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ class BackendFrontnameGenerator
2929
public static function generate()
3030
{
3131
return self::ADMIN_AREA_PATH_PREFIX
32-
. substr(base_convert(rand(0, PHP_INT_MAX), 10, 36), 0, self::ADMIN_AREA_PATH_RANDOM_PART_LENGTH);
32+
. substr(base_convert(random_int(0, PHP_INT_MAX), 10, 36), 0, self::ADMIN_AREA_PATH_RANDOM_PART_LENGTH);
3333
}
3434
}

lib/internal/Magento/Framework/Webapi/ErrorProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public function apiShutdownFunction()
317317
protected function _saveFatalErrorReport($reportData)
318318
{
319319
$this->directoryWrite->create('report/api');
320-
$reportId = abs(intval(microtime(true) * rand(100, 1000)));
320+
$reportId = abs(intval(microtime(true) * random_int(100, 1000)));
321321
$this->directoryWrite->writeFile('report/api/' . $reportId, $this->serializer->serialize($reportData));
322322
return $reportId;
323323
}

pub/errors/processor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ protected function _setReportData($reportData)
463463
public function saveReport($reportData)
464464
{
465465
$this->reportData = $reportData;
466-
$this->reportId = abs(intval(microtime(true) * rand(100, 1000)));
466+
$this->reportId = abs(intval(microtime(true) * random_int(100, 1000)));
467467
$this->_reportFile = $this->_reportDir . '/' . $this->reportId;
468468
$this->_setReportData($reportData);
469469

setup/src/Magento/Setup/Model/Address/AddressDataGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AddressDataGenerator
1818
public function generateAddress()
1919
{
2020
return [
21-
'postcode' => mt_rand(10000, 99999)
21+
'postcode' => random_int(10000, 99999)
2222
];
2323
}
2424
}

setup/src/Magento/Setup/Model/DataGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ protected function readData()
6767
*/
6868
public function generate($minAmountOfWords, $maxAmountOfWords, $key = null)
6969
{
70-
$numberOfWords = mt_rand($minAmountOfWords, $maxAmountOfWords);
70+
$numberOfWords = random_int($minAmountOfWords, $maxAmountOfWords);
7171
$result = '';
7272

7373
if ($key === null || !array_key_exists($key, $this->generatedValues)) {
7474
for ($i = 0; $i < $numberOfWords; $i++) {
75-
$result .= ' ' . $this->dictionaryData[mt_rand(0, count($this->dictionaryData) - 1)];
75+
$result .= ' ' . $this->dictionaryData[random_int(0, count($this->dictionaryData) - 1)];
7676
}
7777
$result = trim($result);
7878

0 commit comments

Comments
 (0)