ar_EG
2 years ago
ar_JO
2 years ago
ar_SA
2 years ago
at_AT
2 years ago
bg_BG
2 years ago
bn_BD
2 years ago
cs_CZ
2 years ago
da_DK
2 years ago
de_AT
2 years ago
de_CH
2 years ago
de_DE
2 years ago
el_CY
2 years ago
el_GR
2 years ago
en_AU
2 years ago
en_CA
2 years ago
en_GB
2 years ago
en_HK
2 years ago
en_IN
2 years ago
en_NG
2 years ago
en_NZ
2 years ago
en_PH
2 years ago
en_SG
2 years ago
en_UG
2 years ago
en_US
2 years ago
en_ZA
2 years ago
es_AR
2 years ago
es_ES
2 years ago
es_PE
2 years ago
es_VE
2 years ago
et_EE
2 years ago
fa_IR
2 years ago
fi_FI
2 years ago
fr_BE
2 years ago
fr_CA
2 years ago
fr_CH
2 years ago
fr_FR
2 years ago
he_IL
2 years ago
hr_HR
2 years ago
hu_HU
2 years ago
hy_AM
2 years ago
id_ID
2 years ago
is_IS
2 years ago
it_CH
2 years ago
it_IT
2 years ago
ja_JP
2 years ago
ka_GE
2 years ago
kk_KZ
2 years ago
ko_KR
2 years ago
lt_LT
2 years ago
lv_LV
2 years ago
me_ME
2 years ago
mn_MN
2 years ago
ms_MY
2 years ago
nb_NO
2 years ago
ne_NP
2 years ago
nl_BE
2 years ago
nl_NL
2 years ago
pl_PL
2 years ago
pt_BR
2 years ago
pt_PT
2 years ago
ro_MD
2 years ago
ro_RO
2 years ago
ru_RU
2 years ago
sk_SK
2 years ago
sl_SI
2 years ago
sr_Cyrl_RS
2 years ago
sr_Latn_RS
2 years ago
sr_RS
2 years ago
sv_SE
2 years ago
th_TH
2 years ago
tr_TR
2 years ago
uk_UA
2 years ago
vi_VN
2 years ago
zh_CN
2 years ago
zh_TW
2 years ago
Address.php
2 years ago
Barcode.php
2 years ago
Base.php
2 years ago
Biased.php
2 years ago
Color.php
2 years ago
Company.php
2 years ago
DateTime.php
2 years ago
File.php
2 years ago
HtmlLorem.php
2 years ago
Image.php
2 years ago
Internet.php
2 years ago
Lorem.php
2 years ago
Medical.php
2 years ago
Miscellaneous.php
2 years ago
Payment.php
2 years ago
Person.php
2 years ago
PhoneNumber.php
2 years ago
Text.php
2 years ago
UserAgent.php
2 years ago
Uuid.php
2 years ago
Biased.php
72 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @license MIT |
| 4 | * |
| 5 | * Modified by impress-org on 23-January-2024 using Strauss. |
| 6 | * @see https://github.com/BrianHenryIE/strauss |
| 7 | */ |
| 8 | |
| 9 | namespace Give\Vendors\Faker\Provider; |
| 10 | |
| 11 | class Biased extends Base |
| 12 | { |
| 13 | /** |
| 14 | * Returns a biased integer between $min and $max (both inclusive). |
| 15 | * The distribution depends on $function. |
| 16 | * |
| 17 | * The algorithm creates two doubles, x ∈ [0, 1], y ∈ [0, 1) and checks whether the |
| 18 | * return value of $function for x is greater than or equal to y. If this is |
| 19 | * the case the number is accepted and x is mapped to the appropriate integer |
| 20 | * between $min and $max. Otherwise two new doubles are created until the pair |
| 21 | * is accepted. |
| 22 | * |
| 23 | * @param int $min Minimum value of the generated integers. |
| 24 | * @param int $max Maximum value of the generated integers. |
| 25 | * @param callable $function A function mapping x ∈ [0, 1] onto a double ∈ [0, 1] |
| 26 | * |
| 27 | * @return int An integer between $min and $max. |
| 28 | */ |
| 29 | public function biasedNumberBetween($min = 0, $max = 100, $function = 'sqrt') |
| 30 | { |
| 31 | do { |
| 32 | $x = mt_rand() / mt_getrandmax(); |
| 33 | $y = mt_rand() / (mt_getrandmax() + 1); |
| 34 | } while (call_user_func($function, $x) < $y); |
| 35 | |
| 36 | return (int) floor($x * ($max - $min + 1) + $min); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * 'unbiased' creates an unbiased distribution by giving |
| 41 | * each value the same value of one. |
| 42 | * |
| 43 | * @return int |
| 44 | */ |
| 45 | protected static function unbiased() |
| 46 | { |
| 47 | return 1; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * 'linearLow' favors lower numbers. The probability decreases |
| 52 | * in a linear fashion. |
| 53 | * |
| 54 | * @return int |
| 55 | */ |
| 56 | protected static function linearLow($x) |
| 57 | { |
| 58 | return 1 - $x; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * 'linearHigh' favors higher numbers. The probability increases |
| 63 | * in a linear fashion. |
| 64 | * |
| 65 | * @return int |
| 66 | */ |
| 67 | protected static function linearHigh($x) |
| 68 | { |
| 69 | return $x; |
| 70 | } |
| 71 | } |
| 72 |