Question about 'random' -
Shetch - 07.04.2012
Hey guys!
I have a question about the 'random' function.
How could i make the server select a random number for example in between 600 and 800.
Like the random for example would be 756. It would never go over 800 or below 600.
Respuesta: Question about 'random' -
admantis - 07.04.2012
pawn Код:
stock randomrange( min, max ) {
return min + random( max );
}
use common sense and you will understand it
Re: Respuesta: Question about 'random' -
Shetch - 07.04.2012
Quote:
Originally Posted by admantis
pawn Код:
stock randomrange( min, max ) { return min + random( max ); }
use common sense and you will understand it
|
Sorry bor being retarded.
Uhh... thanks.
Respuesta: Re: Respuesta: Question about 'random' -
admantis - 07.04.2012
Quote:
Originally Posted by Shetch
Sorry bor being retarded.
Uhh... thanks.
|
that went out harsher than I intended.. I mean that the code is easy to understand if you put a bit of brain into it.
Re: Respuesta: Re: Respuesta: Question about 'random' -
Shetch - 07.04.2012
Quote:
Originally Posted by admantis
that went out harsher than I intended.. I mean that the code is easy to understand if you put a bit of brain into it.
|
Oh, i thought it was ment as an insult.
It's not really working for me. :/
Код:
[00:26:42] 1088
[00:26:43] 988
[00:26:44] 871
[00:26:45] 1026
[00:26:46] 1115
[00:26:47] 1138
[00:26:48] 938
[00:26:49] 600
[00:26:50] 855
[00:26:52] 976
[00:26:53] 1174
[00:26:54] 667
[00:26:55] 997
[00:26:56] 728
[00:26:57] 664
[00:26:58] 858
[00:26:59] 793
[00:27:00] 908
here's the code that's set on a one second timer.
Код:
new number;
number = randomrange(600, 800);
printf("%d", number);
Respuesta: Question about 'random' -
admantis - 07.04.2012
I'm sorry!
pawn Код:
stock randomrange( min, max ) {
return random( max - min + 1) + min;
}
got confused.
Re: Question about 'random' -
Jonny5 - 07.04.2012
thats because random returns a number between 0 and max
so using his code it will get a random range between 0 and 800
and then it adds 600 to it... not sure how it was ever suppose to work
this should work not tested.
edit:
+1
pawn Код:
stock randomrange( min, max ) {
return min + random( max - min) + 1;
}
Re: Question about 'random' -
ReneG - 07.04.2012
Or this...?
pawn Код:
#define randomEx(%0,%1) (random((%1) - (%0)) + (%0))
Just used my common sense, dunno if it works.