Advanced Random();
#1

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.
Reply
#2

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);
Reply
#3

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
Reply
#4

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.
Reply
#5

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
Reply
#6

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

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?
Reply
#8

Oh yeah, haven't seen ******'s code.

Sorry.
Reply
#9

Thanks all!
Reply
#10

FIXED!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)