• Регистрация на форуме отключена.
    Она будет открываться первого числа каждого месяца на 24 часа.

    Если необходимо - пишите админу группы Dev-CS в Telegram-чате.

Get better random number

Сообщения
97
Реакции
21
hi guys! as most of you probably know random_num() are not getting really random numbers on every call (because its 'too much' repetitive), can anyone help with some pseudo-random num function/code ? *random() is even worse than random_num(), can be seen here: https://github.com/alliedmodders/amxmodx/issues/545#issuecomment-418216005

my idea was, because i want to get random player from all alive players,currently code is:

Код:
random_num( 1, alive_players )
//if its called on every round start, results will be like ~10 of 15 the same

//idea:

new rand = random_num( 1, alive_players )
if( rand > 2 )
{
return random_num( 1, ( random_num( 2, rand ) )
}
else
{
return rand
}
but im not sure if its convinient..anyone got better solution ? ps: RandomX module is not for linux, so cant work with it
 
Сообщения
97
Реакции
21
Do you have any experience with using it?
if i try: xs_irand_range( 1, 99 ) im getting error on compiling:
Empty statament in xs.inc line: 118

from xs.inc:
Код:
stock xs_irand_range(pmin, pmax)
{
    xs_assert_dbg(pmax - pmin >= 0, "xs_irand_range: pmin > pmax"); //this is that line
    new i = pmin + floatround(xs_frand() * float(pmax - pmin));
    if (i > pmax)
        i = pmax;
    return i;
}
Also tryed to use xs_irand() but it even doesnt set max possible num (like random(n))...these few are really confusing funcs from xs :D
 
Сообщения
1,462
Реакции
1,253
Помог
22 раз(а)
jocasrb, comment this line for avoid assert check.
 
Сообщения
97
Реакции
21
fl0wer spasibo for that.

tryed xs_irand_range( 1, 99 )..but on every map start first calling this fucntion gives the same result...that not random i guess :/
 
Сообщения
2,461
Реакции
2,671
Помог
60 раз(а)
jocasrb, you can try repeat random function at map start with seconds count (for example) for changing seed. Because it's pseudo random.
 
Сообщения
97
Реакции
21
fantom, i tryed something but no matter what, with xs_irand_range i always get same results from start map...if you can give any example, it would help (also i commented line in .include)

on lan random_num( 1, 99 ) gives 'random' nums, but on 30 players, 4-5 rounds one player is repeated, which isnt the real random (im using if random_num > 85 -> player is selected)

to me, random_num( 1, random_num( 2, 99 ) seems more 'random'...will see...
 
Сообщения
2,461
Реакции
2,671
Помог
60 раз(а)
jocasrb, take a look at here WarmUp (Prepare_Item).
Or another way is to get current seconds in time and make random with this count
Код:
new secs; time(.second = secs);
    for (new i; i < secs;i++) {
        random(10000);
    }
Also one hack is to use a larger numbers. For example:
Код:
random(1000) % 3
It give you a random 0-2.

It's not a best methods. But don't forget random is pseudo
 
Сообщения
97
Реакции
21
fantom thanks for explanation!
How i understood,

if( random_num( 1000 ) % 3 == 0 )

Is really better than my prevously attempts?
 
Сообщения
97
Реакции
21
after 1y 6months, why not new solution:
Код:
new plrs[ 32 ], pnum
get_players( plrs, pnum, "ch" )

iRandom = pnum % 5 (meaning you will get nums from 0 to 4)
cant see better 'human' factor than players online, maybe it will help for someone
 
Сообщения
97
Реакции
21
irrumabo_me_nomen Yeah, even a only 'minute' number of current time is better cuz get players always gives 32/32 :p

What is the idea for 'player action' ?
 
Сообщения
147
Реакции
58
Помог
1 раз(а)
jocasrb, You can get the number based on click rate for example or based on some other action depending on the player.
You can also get into account the frequency selection of numbers. If the frequency is too high for the selected number, then select the one with the minimum frequency.
 
Сообщения
97
Реакции
21
Yeah, interesting observation! I will stick with get_systime()/get_gametime() its enoughly for this puprose. Spasibo!
 

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу