/    Sign up×
Community /Pin to ProfileBookmark

How to calculate percentages of items based on rarity and amount

(I asked this in a different post a bit ago however it wasn’t entirely focused on just this problem, so I’m making a new post.)

Basically, how can I calculate percentages of items based on rarity (e.g. Uncommon, Rare, Epic, legendary, etc.) and amount? I’m making percentage-based things on my website and it’s really hard to have to manually distribute them, so I want some sort of calculator formula or math script that I can give a rarity or an array of items and their rarities and get a percentage for each of them. Thanks

to post a comment

10 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 16.2022 — > @Bost#1642557 get a percentage for each of them

For me, that's too vague. I need to see an example set of data, and what the resulting "percentages" should be (or some other more specific explanation that would lead to understanding the actual requirement).
Copy linkTweet thisAlerts:
@BostauthorFeb 16.2022 — @NogDog#1642558 Here is the array:
``js<i>
</i>const SquidGamePlinks = [
"Player (Uncommon)",
"Worker (Rare)",
"Red Light/Green Light Doll (Epic)",
"Guard (Legendary)"
]<i>
</i>
``


I want to somehow calculate the percentage out of 100 for each item without needing to distribute them manually since that's really hard.
Copy linkTweet thisAlerts:
@daveyerwinFeb 16.2022 — calculate the percentage out of 100 for each item without needing to distribute them manually

what percentage out of 100 would you desire for each item ?
Copy linkTweet thisAlerts:
@BostauthorFeb 16.2022 — > @DaveyErwin#1642591 what percentage out of 100 would you desire for each item ?

No idea. Just enough that is based on its rarity and gets the total to 100.
Copy linkTweet thisAlerts:
@daveyerwinFeb 17.2022 — ``<i>
</i>open console in developers tools
uncommon must be highest Number
each entry must be less than the one above
&lt;form&gt;
&lt;style scoped&gt;
form{width:10em}
&lt;/style&gt;
&lt;fieldset&gt;
&lt;legend&gt;values&lt;/legend&gt;
&lt;label for=nop&gt; number of Players (Uncommon) &lt;/label&gt;
&lt;input id=nop value=0&gt;
&lt;label for=now&gt; number of Workers (Rare) &lt;/label&gt;
&lt;input id=now value=0&gt;
&lt;label for=nor&gt; number of Red Light/Green Lights, Dolls (Epic) &lt;/label&gt;
&lt;input id=nor value=0&gt;
&lt;label for=nog&gt; number of Guards (Legendary) &lt;/label&gt;
&lt;input id=nog value=0&gt;
&lt;/fieldset&gt;
&lt;fieldset&gt;
&lt;legend&gt;Calculate&lt;/legend&gt;
&lt;button id=but&gt;---&lt;/button&gt;
&lt;/fieldset&gt;
&lt;/form&gt;
&lt;___script&gt;
oninput=function(e){
let a = e.target;
let b = e.target.value;
if(isNaN(b))a.value = b.replace(b[b.length-1],'');
if((nop.value*now.value*nor.value*nog.value) &amp;&amp;
(+nop.value) &gt; (+now.value) &amp;&amp; (+now.value) &gt; (+nor.value) &amp;&amp; (+nor.value) &gt; (+nog.value)
){
but.disabled = false;
but.textContent='SUBMIT';
}else {
but.disabled = true;
but.textContent='---';
};
}
onsubmit = function(e){
e.preventDefault();
var num = +nop.value+(+now.value)+(+nor.value)+(+nog.value);
var step = 1/num;
var steps = [];
var offset=Math.sin(step);
steps.push(offset);
for(let i=1;i&lt;num;i++){
let a = Math.sin(step*i)+steps[i-1];
offset += a;
steps.push(a);
}
offset = 100 / offset;
for(let i=0;i&lt;num;i++)steps[i]=steps[i]*offset;
var targets=[];
for(let i=0;i&lt;num;i++){
targets[i]={};
targets[i].perCent=steps[i];
let b="Uncommon";
if(steps[i] &lt; steps[2]*.5){
b="legendary"
}
else if(steps[i] &lt; steps[num-1]/10){
b="epic"
}
else if(steps[i] &lt; steps[num-1]/3){
b="rare"
}
targets[i].rareity=b;
}
console.log(targets);
}
&lt;__/script&gt;<i>
</i>
``
Copy linkTweet thisAlerts:
@BostauthorFeb 17.2022 — @DaveyErwin#1642619 When I type it, it grays out the button.
Copy linkTweet thisAlerts:
@daveyerwinFeb 19.2022 — > @Bost#1642649 When I type it, it grays out the button.

thats a feature

it is only active when the

numbers are in descending order
Copy linkTweet thisAlerts:
@BostauthorFeb 19.2022 — @DaveyErwin#1642667 Oh ok. But what if I only have 1 of each? I wouldn't just divide 100 by 4 because only 1 is uncommon, 1 is rare, one is epic, and 1 is legendary. And an uncommon is not the same chance of getting as a legendary.
Copy linkTweet thisAlerts:
@BostauthorFeb 21.2022 — Bump
Copy linkTweet thisAlerts:
@SempervivumFeb 21.2022 — @Bost#1642678
>what if I only have 1 of each?

Calculating statistics or rarities or probabilities can be performed only when there is a certain amount of data. Check if there are at least, say 20 items and, if there are not, omit the calculation and output an appropriate message .
×

Success!

Help @Bost spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...