random numbers
#12

Well fella's, PAWN's random source code is all over GitHub. In fact I even converted it to PAWN. You could easily add another function that determines the next random number without seeding it for the next call.

pawn Код:
stock next_random(max)
{
    if(simplex_seed == INITIAL_SEED)
        simplex_seed = gettime();
   
    new lo, hi, ll, lh, hh, hl;
    new result;

    lo = simplex_seed    & 0xffff;
    hi = simplex_seed   >> 16;
    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 &= ~(-2147483647);
   
    if (max != 0)
        result %= max;
   
    return result;
}
I'll prolly just add this to that repo...



EDIT: Keep in mind, the PAWN version is obviously slower than the original simply because it's in PAWN. But with the code converted to PAWN we can seed the next random number, add a minimum value, or even check the next value before seeding it again (like so).
Reply


Messages In This Thread
random numbers - by n00blek - 20.01.2018, 12:05
Re: random numbers - by wallee - 20.01.2018, 12:07
Re: random numbers - by VeryTallMidget - 20.01.2018, 13:02
Re: random numbers - by RogueDrifter - 20.01.2018, 13:44
Re: random numbers - by edyun - 20.01.2018, 14:44
Re: random numbers - by Sew_Sumi - 20.01.2018, 15:06
Re: random numbers - by Redirect Left - 20.01.2018, 16:21
Re: random numbers - by Whillyrez - 20.01.2018, 16:22
Re: random numbers - by n00blek - 20.01.2018, 17:52
Re: random numbers - by VeryTallMidget - 21.01.2018, 18:52
Re: random numbers - by Sew_Sumi - 21.01.2018, 22:56
Re: random numbers - by Crayder - 22.01.2018, 02:49

Forum Jump:


Users browsing this thread: 1 Guest(s)