Percents
#1

Hello I want to ask, for example is it possible to make code example I want to have a 20% chance to become IGInfo [playerid] [Owner] = 1; and in the other 80% to nothing happens.
Could this be done somehow?
Reply
#2

pawn Код:
switch (random(10))
{
    case 0, 1:
    {
        // 20%
    }
}
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
switch (random(10))
{
    case 0, 1:
    {
        // 20%
    }
}
is there

PHP код:
case 01
are percent options ? example
PHP код:
 case 0
is 10% ? and for 5% how to make ?
Reply
#4

Using 10 as max in random function will let you to use it as 10, 20 .. 90, 100 percent. And yes, using case 0 is like using 10% for the above example.

However for using 5%, you'll need to change the max to 100 and check if it's the first 5 digits (0-4), then it's 5 percent.
pawn Код:
switch (random(100))
{
    case 0 .. 4:
    {
        // 5%
    }
}
Reply
#5

Thanks you i will try it and post if i have any problems
Reply
#6

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
switch (random(10))
{
    case 0, 1:
    {
        // 20%
    }
}
Hello again, I want to ask does this code generate 10 or 11 numbers in the sense of adding 0 as another number + those from 1 to 10 are 11 or so?

I ask because there wondering one thing and do not know whether it is so

with 27 numbers
PHP код:
    switch (random(27-RLTnfo[playerid][Chance]))
    {
        case 
0,1//7,40% - 28,57% by 20 level Chance
        
{
        
//code
        
}
    } 
or

with 27 numbers plus a zero to the numbers from 1 to 27 = 28
PHP код:
    switch (random(27-RLTnfo[playerid][Chance]))
    {
        case 
0,1//7.14% - 25% by 20 level Chance
        
{
        
//code
        
}
    } 
Which of these is the 2 correct?
Reply
#7

Because the indexes in PAWN starts from 0 when you have size/max a number N, it's always: 0 to (N-1).

For example, using 10 is 0-9 (which is 10 in total).

I'm not sure if you can use floating-point numbers for that case.
Reply
#8

Ah, so the first one is true?
Here it
PHP код:
    switch (random(27-RLTnfo[playerid][Chance])) 
    { 
        case 
0,1//7,40% - 28,57% by 20 level Chance 
        

        
//code 
        

    } 
Reply
#9

No, it's not. The max value in random is unknown and with case 0/1 you won't get 7.40% - 28.57% percent.
Reply
#10

I think you do not understand exactly, then these percentages which I have written have a chance to drop these numbers by random (27) rates to fall 0 or 1 is 7.40% and at Level 20 Chance parameter, which removes 20 index and becomes random (7) the chance to fall 0 or 1 becomes 28.57%
Reply


Forum Jump:


Users browsing this thread: 7 Guest(s)