Setting random amount (Min-Max)
#1

As you might see im using random number and max is 250. How may i set it to be random from 100-250 ?

PHP код:
public OnPlayerEnterCheckpoint(playerid)
{
    if(
g_var[playerid] == && IsPlayerInRangeOfPoint(playerid5,  2789.6619, -2517.810516.1509))
    {
            
DisablePlayerCheckpoint(playerid);
            new 
vehicleid GetPlayerVehicleID(playerid);
            new 
string[128], amount;
            
amount random (250);
            
format(stringsizeof(string), "*You've earned {FF6347}$%d{33CCFF} from dropping a car!"amount);
            
SendClientMessage(playeridCOLOR_LIGHTBLUEstring);
            
GiveDodMoney(playeridamount);
            
SetVehicleToRespawn(vehicleid);
            
g_var[playerid] = 1;
            
SetTimerEx("CountDown",1200*1000false"d"playerid);
        } 
Reply
#2

define:
pawn Код:
#define MIN_RAND 100
#define MAX_RAND 250
Try to change this:
pawn Код:
amount = random (250);
To:
pawn Код:
amount = random (MIN_RAND,MAX_RAND);
Reply
#3

On this line i have the following warn:
Код HTML:
amount = random (MIN_RAND,MAX_RAND);
Код HTML:
warning 202: number of arguments does not match definition
Definition looks like this.
Код HTML:
//Dropcar
new g_var[MAX_PLAYERS];
#define MIN_RAND 100
#define MAX_RAND 250
Reply
#4

Quote:
Originally Posted by AmirRFCNR
Посмотреть сообщение
...
Are you trying to gain rep or something? Because posting wrong information isn't the way to do it. Do your research first. "Try this" and "Try that" with methods that are obviously wrong (to the trained eye) isn't going to help anyone.

@OP: use this function:
pawn Код:
minrandom(min, max)
    return min + random(max - min);
Reply
#5

pawn Код:
stock GetRandomBetween(min, max)
{
    new num = random(max);
    if(num > min) return num;
    else if(num < num) return GetRandomBetween(min, max);
}
will work but may take time

edit: Vince got better thing :P
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
Are you trying to gain rep or something? Because posting wrong information isn't the way to do it. Do your research first. "Try this" and "Try that" with methods that are obviously wrong (to the trained eye) isn't going to help anyone.

@OP: use this function:
pawn Код:
minrandom(min, max)
    return min + random(max - min);
Can you explain me abit more about this min max random amount ?;/
Reply
#7

Quote:
Originally Posted by PMH
Посмотреть сообщение
pawn Код:
stock GetRandomBetween(min, max)
{
    new num = random(max);
    if(num > min) return num;
    else if(num < num) return GetRandomBetween(min, max);
}
will work but may take time

edit: Vince got better thing :P
Yeah i noticed but the thing is that Vince didnt explain anything and i have no idea how to use it :/
Reply
#8

Quote:
Originally Posted by weedxd
Посмотреть сообщение
On this line i have the following warn:
Код HTML:
amount = random (MIN_RAND,MAX_RAND);
Код HTML:
warning 202: number of arguments does not match definition
Definition looks like this.
Код HTML:
//Dropcar
new g_var[MAX_PLAYERS];
#define MIN_RAND 100
#define MAX_RAND 250
i have this code too will help you
pawn Код:
stock randomnumber(min, max)
{
    new rand = random(max-min)+min;
    return rand;
}
and change
pawn Код:
amount = randomnumber(MIN_RAND,MAX_RAND);
that working for me
Reply
#9

Alright, let's suppose that you pass 100 and 250 to the function. What you would end up with (internally) is this:
pawn Код:
return 100 + random(250 - 100)
Which in turn gets simplified to
pawn Код:
return 100 + random(150)
Now, as you know the random function now returns a random value between 0 and 150. Let's suppose the random value is 0. The 100 from before gets added and 100 is returned. Let's suppose the random value is 149. Again, the 100 from before gets added and 249 is returned.

Usage is just the same as the regular random function.

pawn Код:
new randomNumber = minrandom(100, 250);
Reply
#10

Issue fixed used my brain abit and found an example in the script.

Код HTML:
amount = 100+random(250);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)