Raised This Month: $ Target: $400
 0% 

%, chance, random


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Heyka
Member
Join Date: Mar 2012
Old 06-26-2012 , 15:14   %, chance, random
Reply With Quote #1

Hello guys!
I'm wondering how to calculate ACCURATE chance to do something. At the moment I use that script but it's lame and doesn't calculate right chance.
Code:
	
cvar_slash_chance = register_cvar("bs_slash_chance", "33")

static random_num0
random_num0 = random_num(0, 100)
if(random_num0 <= get_pcvar_num(cvar_slash_chance))
Of course it's just cut from whole code.

Can anyone manage how to be more accurate with setting %chance?
Heyka is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-26-2012 , 15:18   Re: %, chance, random
Reply With Quote #2

That is how to do it. If you want an alternative, have a look at the random functions from xs.inc.

Code:
xs_seed(seed)
xs_irand()
Float:xs_frand()
xs_irand_range(pmin, pmax)
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Heyka
Member
Join Date: Mar 2012
Old 06-26-2012 , 15:31   Re: %, chance, random
Reply With Quote #3

Sorry, but I'm new in Pawn and I don't know really what structure should I build. Would you help me?
Heyka is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-26-2012 , 15:44   Re: %, chance, random
Reply With Quote #4

so xs_irand_range gives better results than random_num i presume ?
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Heyka
Member
Join Date: Mar 2012
Old 06-26-2012 , 15:48   Re: %, chance, random
Reply With Quote #5

I bet. But can you give me example of usage?
Heyka is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-26-2012 , 16:25   Re: %, chance, random
Reply With Quote #6

Quote:
Originally Posted by ConnorMcLeod View Post
so xs_irand_range gives better results than random_num i presume ?
It is the same, I presume:

Code:
static cell AMX_NATIVE_CALL core_random(AMX *amx,cell *params)
{
    unsigned long lo, hi, ll, lh, hh, hl;
    unsigned long result;

    /* one-time initialization (or, mostly one-time) */
    #if !defined SN_TARGET_PS2 && !defined _WIN32_WCE
        if (IL_StandardRandom_seed == INITIAL_SEED)
            IL_StandardRandom_seed=(unsigned long)time(NULL);
    #endif

    lo = IL_StandardRandom_seed & 0xffff;
    hi = IL_StandardRandom_seed >> 16;
    IL_StandardRandom_seed = IL_StandardRandom_seed * IL_RMULT + 12345;
    ll = lo * (IL_RMULT  & 0xffff);
    lh = lo * (IL_RMULT >> 16    );
    hl = hi * (IL_RMULT  & 0xffff);
    hh = hi * (IL_RMULT >> 16    );
    result = ((ll + 12345) >> 16) + lh + hl + (hh << 16);
    result &= ~LONG_MIN;        /* remove sign bit */
    if (params[1]!=0)
        result %= params[1];
    return (cell)result;
}
The difference is that you can provide a seed.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 06-26-2012 at 16:28.
Exolent[jNr] is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-26-2012 , 17:03   Re: %, chance, random
Reply With Quote #7

I though seed was hardcoded seeing xs code.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-26-2012 , 17:16   Re: %, chance, random
Reply With Quote #8

Quote:
Originally Posted by ConnorMcLeod View Post
I though seed was hardcoded seeing xs code.
It is if you don't change it with xs_seed().
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Heyka
Member
Join Date: Mar 2012
Old 06-26-2012 , 17:30   Re: %, chance, random
Reply With Quote #9

I feel like

when reading it. Can anyone put new function and cvar, please?
Heyka is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-26-2012 , 18:54   Re: %, chance, random
Reply With Quote #10

Quote:
Originally Posted by Heyka View Post
I feel like when reading it. Can anyone put new function and cvar, please?
Your original code will work just fine. However, if you want the code to be [more] correct, you need to change the 100 to 99.
__________________
fysiks is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:15.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode