Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
framework
Math
Random.php
Go to the documentation of this file.
1
<?php
6
namespace
Magento\Framework\Math
;
7
8
use
Magento\Framework\Exception\LocalizedException
;
9
use
Magento\Framework\Phrase
;
10
17
class
Random
18
{
22
const
CHARS_LOWERS
=
'abcdefghijklmnopqrstuvwxyz'
;
23
24
const
CHARS_UPPERS
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
;
25
26
const
CHARS_DIGITS
=
'0123456789'
;
27
39
public
function
getRandomString
($length, $chars =
null
)
40
{
41
$str =
''
;
42
if
(
null
=== $chars) {
43
$chars = self::CHARS_LOWERS.self::CHARS_UPPERS.self::CHARS_DIGITS;
44
}
45
46
$charsMaxKey = mb_strlen($chars) - 1;
47
for
(
$i
= 0;
$i
< $length;
$i
++) {
48
$str .= $chars[
self::getRandomNumber
(0, $charsMaxKey)];
49
}
50
51
return
$str;
52
}
53
62
public
static
function
getRandomNumber
($min = 0, $max =
null
)
63
{
64
if
(
null
=== $max) {
65
$max = mt_getrandmax();
66
}
67
68
if
($max < $min) {
69
throw
new
LocalizedException
(
new
Phrase
(
'Invalid range given.'
));
70
}
71
72
return
random_int($min, $max);
73
}
74
82
public
function
getUniqueHash
(
$prefix
=
''
)
83
{
84
return
$prefix
. $this->
getRandomString
(32);
85
}
86
}
Magento\Framework\Exception\LocalizedException
Definition:
LocalizedException.php:17
Magento\Framework\Math
Definition:
Calculator.php:6
Magento\Framework\Math\Random\getRandomNumber
static getRandomNumber($min=0, $max=null)
Definition:
Random.php:62
Magento\Framework\Math\Random\CHARS_UPPERS
const CHARS_UPPERS
Definition:
Random.php:24
$prefix
$prefix
Definition:
name.phtml:25
Magento\Framework\Math\Random\getUniqueHash
getUniqueHash($prefix='')
Definition:
Random.php:82
Magento\Framework\Math\Random
Definition:
Random.php:17
Magento\Framework\Phrase
Definition:
Phrase.php:17
Magento\Framework\Phrase
Magento\Framework\Math\Random\getRandomString
getRandomString($length, $chars=null)
Definition:
Random.php:39
Magento\Framework\Math\Random\CHARS_LOWERS
const CHARS_LOWERS
Definition:
Random.php:22
Magento\Framework\Math\Random\CHARS_DIGITS
const CHARS_DIGITS
Definition:
Random.php:26
$i
$i
Definition:
gallery.phtml:31