Percentage?
#1

Hello everybody, so let`s start, I have idea about some gift boxes. But I want to make percentage of getting some rare things like 1,000,000 score, but I don`t know how should I do it? Should I do it via switch function or if? Probably it`s harder way to made them via if function but I really want to know how should I create that. If anyone have idea how that should looks like please post comment. Thank you
Reply
#2

1. Create an array of that things, for example:
PHP код:
{
  { 
int thingOneint probablity },
  { 
int thingTwoint probablity },
  ...

2. Sum all probablities
3. Get random number RAND from 0 to sum probablity
4. Go through array and accumulate probablities
5. When probablity is bigger than RAND, give last thing in array to player

Probablity is an integer. The bigger it is, the bigger is the probablity of getting this item in random

For example:
{ MONEY_1000, 5 },
{ SCORE_1000000, 1 },
{ WEAPON_DEAGLE, 3 }
Reply
#3

Lets say you have chance of 5 in a 1000 to get a certain item, so 0.5%.
Take a random number between 1 and 1000 (both included).
If this number exceeds a certain threshold (1000 - 5 = 995 in this case), the item is given to the player.

Edit: prinside was faster to reply, basically what he said
Reply
#4

Quote:
Originally Posted by Freaksken
Посмотреть сообщение
Lets say you have chance of 5 in a 1000 to get a certain item, so 0.5%.
Take a random number between 1 and 1000 (both included).
If this number exceeds a certain threshold (1000 - 5 = 995 in this case), the item is given to the player.

Edit: prinside was faster to reply, basically what he said
5 in 1000 is 0.005% not 0.5%, 0.5% is 50% lol


doing if(random(1000) < 50) would be 5% chance


Quote:
Originally Posted by prineside
Посмотреть сообщение
1. Create an array of that things, for example:
PHP код:
{
  { 
int thingOneint probablity },
  { 
int thingTwoint probablity },
  ...

2. Sum all probablities
3. Get random number RAND from 0 to sum probablity
4. Go through array and accumulate probablities
5. When probablity is bigger than RAND, give last thing in array to player

Probablity is an integer. The bigger it is, the bigger is the probablity of getting this item in random

For example:
{ MONEY_1000, 5 },
{ SCORE_1000000, 1 },
{ WEAPON_DEAGLE, 3 }
So basically, instead of having a 2d array, i would do a 3d array.

{ type, out_of, prob }

Where type = what to give them (such as a function that contains a switch that will give them a reward based on the id). out_of = the total number such as 1000, and prob = 5 for 5 out of 1000.

This way you would be able to have indexed types, along with different percentages.


You could also do something like,

{ type, 50000, 1 } or any other combination
Reply
#5

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
5 in 1000 is 0.005% not 0.5%, 0.5% is 50% lol
No 50% equals 0.5 (without the % sign).
Thus 0.5% equals 0.005.
When you divide by 100 and add the % sign aswell, you basically do the same action twice because % already means divide by 100.

Proof: https://www.******.be/webhp?sourceid...UTF-8#q=0.5%25
Reply
#6

Quote:
Originally Posted by Freaksken
Посмотреть сообщение
No 50% equals 0.5 (without the % sign).
Thus 0.5% equals 0.005.
When you divide by 100 and add the % sign aswell, you basically do the same action twice because % already means divide by 100.

Proof: https://www.******.be/webhp?sourceid...UTF-8#q=0.5%25
It was a typo chill bruh
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)