Advanced Random(); - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Advanced Random(); (
/showthread.php?tid=525473)
Advanced Random(); -
Juvanii - 12.07.2014
Is it possible to make a function getting specific random numbers?
Example:
pawn Код:
random(400, 300, 123, 453, 111);
And then it'll get random number from these 5 numbers!
OR:
Make a function to get random numbers from min to max then delete some unwanted numbers and let the random choose another!
Example:
pawn Код:
stock RandomEx(min, max)
{
return random(max - min) + min;
}
RandomEx(400, 612);
Then if the random number would be (500, 414 or 523 etc..) for example, so it should re random the min-max numbers and choose another.
Re: Advanced Random(); -
Ihateyou - 12.07.2014
yea?
pawn Код:
new mynumbers[5] = { 12, 42, 52, 69 ,1 } ;
random(mynumbers);
2nd example:
pawn Код:
new randInt;
do
{
randInt = RandomEx(400, 612);
}
while(randInt==500||randInt==414);
Re: Advanced Random(); -
BroZeus - 12.07.2014
well u could get that
1. you need this
https://sampforum.blast.hk/showthread.php?tid=92679
after getting this do like this--
pawn Код:
#include <foreach>
new Iterator:randomnum<50>;
Iter_Add(randomnum, 400);
Iter_Add(randomnum, 300);
Iter_Add(randomnum, 123);
Iter_Add(randomnum, 453);
//like this add number from which you want the random
Iter_Random(randomnum);//this function will return random number from the added numbers || USE THIS
Re: Advanced Random(); -
Juvanii - 12.07.2014
Quote:
Originally Posted by Ihateyou
yea?
pawn Код:
new mynumbers[5] = { 12, 42, 52, 69 ,1 } ;
random(mynumbers);
|
I put 138 numbers between the brackets and i changed the number 5 to 138, so it looks like "new mynumbers[138] ="
And under OnGameModeInIt i added:
pawn Код:
public OnGameModeInit()
{
new TestRandom = random(mynumbers); //line 1182
return 1;
}
but:
Код:
(1182) : error 035: argument type mismatch (argument 1)
Quote:
Originally Posted by BroZeus
well u could get that
1. you need this https://sampforum.blast.hk/showthread.php?tid=92679
after getting this do like this--
pawn Код:
#include <foreach>
new Iterator:randomnum<50>;
Iter_Add(randomnum, 400); Iter_Add(randomnum, 300); Iter_Add(randomnum, 123); Iter_Add(randomnum, 453); //like this add number from which you want the random
Iter_Random(randomnum);//this function will return random number from the added numbers || USE THIS
|
Thanks for replying! i'll also try that if the first method didn't work.
Re: Advanced Random(); -
Ihateyou - 12.07.2014
Quote:
Originally Posted by ******
As for the first version, it would actually be:
pawn Код:
new numbers[5] = {1, 3, 5, 8, 100};
new rand = numbers[random(sizeof (numbers))];
|
ah yes master ****** . Ty.. i forgot random(sizeof());
why am i so bad .. gj
btw this is not really advanced.. lol
Re : Advanced Random(); -
S4t3K - 12.07.2014
The first function you've asked can be easily made.
pawn Код:
random_(...)
{
new array[256];
for(new i = 0; i < numargs(); i++) array[i] = getarg(i);
return array[random(numargs())];
}
Tested with "random_(215, 121, 18, 3, 52, 483);" three times and two different results (the last one was the same as the second).
Re: Re : Advanced Random(); -
Ihateyou - 12.07.2014
Quote:
Originally Posted by S4t3K
The first function you've asked can be easily made.
pawn Код:
random_(...) {
new array[256]; for(new i = 0; i < numargs(); i++) array[i] = getarg(i); return array[random(numargs())]; }
Tested with "random_(215, 121, 18, 3, 52, 483);" three times and two different results (the last one was the same as the second).
|
why u using array didnt u see what ***** posted skrub?
Re : Advanced Random(); -
S4t3K - 12.07.2014
Oh yeah, haven't seen ******'s code.
Sorry.
Re: Advanced Random(); -
Juvanii - 13.07.2014
Thanks all!
Re: Advanced Random(); -
Juvanii - 13.07.2014
FIXED!