Random Number Between... -
Ely - 28.10.2011
How Would I Make It So When You Type /roll
You Get Sent A Message With A Random Number Between 150000 And 300000?
The Code I Made
Код:
if(!strcmp("/roll", cmdtext, true))
{
new string[128];
new cash = (150000 + random(300000));
format(string, sizeof(string), "Number Is: %d",cash);
SendClientMessage(playerid,COLOR_YELLOW,string);
}
Didn't Exactly Work Lul Any Help?
Ellie
Re: Random Number Between... -
admantis - 28.10.2011
pawn Код:
stock random2(min,max) // returns a random value, between min and max.
{
return min + random ( max - min );
}
Re: Random Number Between... -
FUNExtreme - 28.10.2011
Between 150.000 and 300.000?
That is a difference of 150.000, so
pawn Код:
new cash = (150000 + random(150000)); //Minimum of 150000+a maximum random value of 150000 = 300000
will do the trick
Re: Random Number Between... -
Zonoya - 28.10.2011
pawn Код:
if(!strcmp("/roll", cmdtexr, true))
{
new string[128];
new cash = RandomEx(150000, 300000));
format(string, sizeof(string), "Number Is: %d",cash);
SendClientMessage(playerid, COLOR_YELLOW, string);
}
i know this works cause i use this on my server for my work system and it works wonders :P
Re: Random Number Between... -
Kostas' - 28.10.2011
You can define minimim-maximum numbers
pawn Код:
#define MINIMUM_VALUE 2000000
#define MAXIMUM_VALUE 8000000
pawn Код:
new cash = MINIMUM_VALUE + random(MAXIMUM_VALUE-MINIMUM_VALUE);
Re: Random Number Between... -
admantis - 28.10.2011
Kostas' solution is not efficent when you want to do it with different numbers.
Zonoya does not define RandomEx.
FUNExtreme method's sometimes will go beyond 300,000.
I don't want to be a smart-ass but I am pointing out what is wrong.
Re: Random Number Between... -
FUNExtreme - 28.10.2011
Quote:
Originally Posted by admantis
pawn Код:
stock random2(min,max) // returns a random value, between min and max. { return min + random ( max - min ); }
|
That'll do the trick. USE THIS!
Quote:
Originally Posted by FUNExtreme
Between 150.000 and 300.000?
That is a difference of 150.000, so
pawn Код:
new cash = (150000 + random(150000)); //Minimum of 150000+a maximum random value of 150000 = 300000
will do the trick
|
I basicly did the same thing but just without using a function. If you need to do this multiple times, use the function from admantis
Quote:
Originally Posted by Zonoya
pawn Код:
if(!strcmp("/roll", cmdtexr, true)) { new string[128]; new cash = RandomEx(150000, 300000)); format(string, sizeof(string), "Number Is: %d",cash); SendClientMessage(playerid, COLOR_YELLOW, string); }
i know this works cause i use this on my server for my work system and it works wonders :P
|
Since when is RandomEx a default pawn function? It is not, you have it in your script somewhere.
Use the function provided by admantis!
Quote:
Originally Posted by Kostas'
You can define minimim-maximum numbers
pawn Код:
#define MINIMUM_VALUE 2000000 #define MAXIMUM_VALUE 8000000
pawn Код:
new cash = MINIMUM_VALUE + random(MAXIMUM_VALUE-MINIMUM_VALUE);
|
Exactly the same like I said, I repeat: "use the function from admantis"
Re: Random Number Between... -
Ely - 28.10.2011
Quote:
Originally Posted by Zonoya
pawn Код:
if(!strcmp("/roll", cmdtexr, true)) { new string[128]; new cash = RandomEx(150000, 300000)); format(string, sizeof(string), "Number Is: %d",cash); SendClientMessage(playerid, COLOR_YELLOW, string); }
i know this works cause i use this on my server for my work system and it works wonders :P
|
Thanks But 1 Error Guessing RandomEx Uses A Stock?
Код:
C:\Users\Ellie\Desktop\Server\gamemodes\Game.pwn(788) : error 017: undefined symbol "RandomEx"
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
1 Error.
Re: Random Number Between... -
FUNExtreme - 28.10.2011
Quote:
Originally Posted by admantis
Kostas' solution is not efficent when you want to do it with different numbers.
Zonoya does not define RandomEx.
FUNExtreme method's sometimes will go beyond 300,000.
I don't want to be a smart-ass but I am pointing out what is wrong.
|
Ok, Just a simple question. How can my function ever go above 300.000?! Is there some kind of malfunction in the random function that it goes higher than the given amount? Enlighten me
Re: Random Number Between... -
admantis - 28.10.2011
Quote:
Originally Posted by FUNExtreme
Ok, Just a simple question. How can my function ever go above 300.000?! Is there some kind of malfunction in the random function that it goes higher than the given amount? Enlighten me
|
It doesn't, i apologize.