SA-MP Forums Archive
random numbers - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP (https://sampforum.blast.hk/forumdisplay.php?fid=3)
+--- Forum: General (https://sampforum.blast.hk/forumdisplay.php?fid=13)
+--- Thread: random numbers (/showthread.php?tid=648342)



random numbers - n00blek - 20.01.2018

is there a way to calculate which random number is coming next?
i have choice from 1 to 1000 and i want to know what number is coming next. if there is way please tell me math equasion like R1 + R2 - (R1 + R2)..... if R is random number
idk even what am i doing. this above was just example.
so can anyone solve this for me??
+REP


Re: random numbers - wallee - 20.01.2018

if there was a way there would be a lot of lottery winners


Re: random numbers - VeryTallMidget - 20.01.2018

You want to make "Not-So-Random" number generator ?

That is the whole point of Random, that the next number is unknown.
Add some range to your random generator to make it narrow.


Re: random numbers - RogueDrifter - 20.01.2018

You want to get the outcome of random before executing a process?


Re: random numbers - edyun - 20.01.2018

This is just impossible )))))


Re: random numbers - Sew_Sumi - 20.01.2018

There was a plugin that did real random, as random, isn't random...

https://sampforum.blast.hk/showthread.php?tid=109196

And if you want to know what's next, make 2 randoms... CurrentRandom and NextRandom. Set CurrentRandom to NextRandom, and then random on NextRandom.


Re: random numbers - Redirect Left - 20.01.2018

I'm not sure you understand what 'random' means.


Re: random numbers - Whillyrez - 20.01.2018

Just generate the number anda save it in a variable. Whenever u want to use that number just use the variable


Re: random numbers - n00blek - 20.01.2018

:/ .


Re: random numbers - VeryTallMidget - 21.01.2018

Actually random number generation is a tricky,
for example in visual basic script (vbs), the random function gives same values every time, when "Randomize" is not added before the code...

Code:
for i=1 to 10
S=int(rnd*10)
msgbox S
next
If you want to test it, make new text file, add the code and save it with extension "vbs" (test.vbs).

For me it give values: 7, 5, 5, 2, 3, 7, 0, 7, 8, 7 each time, same numbers in same order

To make it random add Randomize:

Code:
Randomize
for i=1 to 10
S=int(rnd*10)
msgbox S
next
Same goes for Pascal, i remember coding a Video Poker game and same cards were displayed each time.

Code:
procedure TForm1.Button1Click(Sender: TObject);
var
i: byte;
begin
for i:= 0 to 9 do
memo1.Lines.Append(IntToStr(Random(10)));
end;
Without "Randomize;" it gives: (0,0,8,2,2,6,3,1,3,4) each time the program is executed.


Re: random numbers - Sew_Sumi - 21.01.2018

Quote:
Originally Posted by n00blek
Посмотреть сообщение
:/ .
Look at the plugin I linked, and the method I said about having 2 variables.


Re: random numbers - Crayder - 22.01.2018

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).