Get better random number

Сообщения
140
Реакции
28
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
 
Сообщения
140
Реакции
28
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,661
Реакции
1,486
Помог
24 раз(а)
jocasrb, comment this line for avoid assert check.
 
Сообщения
140
Реакции
28
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,491
Реакции
2,790
Помог
61 раз(а)
jocasrb, you can try repeat random function at map start with seconds count (for example) for changing seed. Because it's pseudo random.
 
Сообщения
140
Реакции
28
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,491
Реакции
2,790
Помог
61 раз(а)
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
 
Сообщения
140
Реакции
28
fantom thanks for explanation!
How i understood,

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

Is really better than my prevously attempts?
 
Сообщения
140
Реакции
28
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
 
Сообщения
140
Реакции
28
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' ?
 
Сообщения
225
Реакции
90
Помог
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.
 
Сообщения
140
Реакции
28
Yeah, interesting observation! I will stick with get_systime()/get_gametime() its enoughly for this puprose. Spasibo!
 

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

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