api#326 Сохранить прежний random и чужие JSON токены
deploy-preland / deploy zoomstage.online (push) Successful in 45s
deploy-preland / deploy zoomstage.online (push) Successful in 45s
This commit is contained in:
1 parent
81e189ca67
commit
08febba368
4 files changed
+124
-35
No files matched your search
+26
-10
@@ -50,16 +50,32 @@ function prelandResolveUtm(array $query, array $config): array
|
||||
$value=$query[$key] ?? null;
|
||||
$digit=is_string($value) && preg_match('/\A.{4}([0-9])/us',$value,$match) ? $match[1] : null;
|
||||
if ($digit==='0') {
|
||||
$weights=[];
|
||||
foreach ((array)($settings['weights'] ?? []) as $variant=>$weight) {
|
||||
if ($valid($variant) && is_numeric($weight) && is_finite((float)$weight) && (float)$weight>0) $weights[$variant]=(float)$weight;
|
||||
}
|
||||
$total=array_sum($weights); $digit=$default;
|
||||
if ($total>0 && is_finite($total)) {
|
||||
$point=mt_rand()/(mt_getrandmax()+1.0)*$total;
|
||||
foreach ($weights as $variant=>$weight) {
|
||||
if ($point<$weight) { $digit=(string)$variant; break; }
|
||||
$point-=$weight;
|
||||
// Generic resolver исторически выбирает первый ключ при sum<=0;
|
||||
// cons имеет отдельный контракт: только положительные веса и default.
|
||||
if ($key !== 'cons') {
|
||||
$weights=(array)($settings['weights'] ?? []);
|
||||
$total=array_sum($weights);
|
||||
$digit=$weights ? (string)array_key_first($weights) : $default;
|
||||
if ($total>0 && is_finite((float)$total)) {
|
||||
$point=mt_rand()/mt_getrandmax()*$total; $current=0.0;
|
||||
foreach ($weights as $variant=>$weight) {
|
||||
$current+=(float)$weight;
|
||||
$digit=(string)$variant;
|
||||
if ($point<=$current) break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$weights=[];
|
||||
foreach ((array)($settings['weights'] ?? []) as $variant=>$weight) {
|
||||
if ($valid($variant) && is_numeric($weight) && is_finite((float)$weight) && (float)$weight>0) $weights[$variant]=(float)$weight;
|
||||
}
|
||||
$total=array_sum($weights); $digit=$default;
|
||||
if ($total>0 && is_finite($total)) {
|
||||
$point=mt_rand()/(mt_getrandmax()+1.0)*$total;
|
||||
foreach ($weights as $variant=>$weight) {
|
||||
if ($point<$weight) { $digit=(string)$variant; break; }
|
||||
$point-=$weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user