random_num with exceptions?
I searched all over the forum and the documentation/wiki of AMXX,
but did not find anything that could answer this question. Nevertheless for the case that this has been asked before, I am sorry. My question is, if it is possible to make the random_num function handle exceptions. For example, I want a random number between 0 and 1000. Code:
What would I do in order to have these exceptions? Note that these numbers shall be able to vary and that I do not want to run the same function again and again until an acceptable result has been generated. However, that would look like this, but I do not think that it is good: Code:
Code:
|
Re: random_num with exceptions?
You would need to do something like your random_0_1000 function.
You might want to allow 0 or more excluded numbers instead of hardcoding it to 7. You'll also need to return random_0_1000() in your else statement. |
Re: random_num with exceptions?
Code:
|
Re: random_num with exceptions?
"const exp[]" // What does "const" mean/do ?
"break" // What does this do ? It would be nice if you could give some additional explaination on how your code works, because I am actually getting a headache when trying to understand that in a minute. |
Re: random_num with exceptions?
const - value can't be changed after initialization. if parameter, the function cannot change it.
break - stops a loop from continuing Code:
new num = random_num(0, 1000); |
Re: random_num with exceptions?
Uuuh... Thanks for the Information!
Well I found a better way to fix the main problem I had than a random_num with exceptions. Thanks to all of you anyways, have some Karma. |
| All times are GMT -4. The time now is 06:44. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.