AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   random_num (https://forums.alliedmods.net/showthread.php?t=27965)

wonsae 05-03-2006 21:23

random_num
 
Like if I did
random_num(0,3000)

how long would you think it would take so it picks the random num?

Smokey485 05-03-2006 22:36

Random_num, this is an example of how to use it.

Code:
public eight_ball(id) {     new answer = random_num(0, 4) // chooses random number from 0-4     if(answer == 0)     {         client_print(id,print_chat,"[8BALL] You will drive off a cliff and die.")         return PLUGIN_HANDLED;     }     if(answer == 1)     {         client_print(id,print_chat,"[8BALL] I refuse to answer you!")         return PLUGIN_HANDLED;     }     if(answer == 2)     {         client_print(id,print_chat,"[8BALL] You will grow up and die.")         return PLUGIN_HANDLED;     }     if(answer == 3)     {         client_print(id,print_chat,"[8BALL] You have disturbed by ball-ness")         user_slap(id, 99)         return PLUGIN_HANDLED;     }     if(answer == 4)     {         client_print(id,print_chat,"[8BALL] You will win the next few rounds.")         return PLUGIN_HANDLED;     }     return PLUGIN_HANDLED; }

noob cannon lol 05-03-2006 22:45

Quote:

Originally Posted by Smokey485
+karma me for this

Random_num, this is an example of how to use it.

Code:
public eight_ball(id) {     new answer = random_num(0, 4) // chooses random number from 0-4     if(answer == 0)     {         client_print(id,print_chat,"[8BALL] You will drive off a cliff and die.")         return PLUGIN_HANDLED;     }     if(answer == 1)     {         client_print(id,print_chat,"[8BALL] I refuse to answer you!")         return PLUGIN_HANDLED;     }     if(answer == 2)     {         client_print(id,print_chat,"[8BALL] You will grow up and die.")         return PLUGIN_HANDLED;     }     if(answer == 3)     {         client_print(id,print_chat,"[8BALL] You have disturbed by ball-ness")         user_slap(id, 99)         return PLUGIN_HANDLED;     }     if(answer == 4)     {         client_print(id,print_chat,"[8BALL] You will win the next few rounds.")         return PLUGIN_HANDLED;     }     return PLUGIN_HANDLED; }

He didn't ask how to use it. He asked how long it would take generate the number.

This is a trivial task for any CPU and should be completed in less then a millisecond.

c0rdawg 05-04-2006 00:02

smokey do you just take other pieces of plugins and post them :roll: Anyways that had nothing to do with his post, and neither does this... sorry

Smokey485 05-04-2006 00:11

Quote:

Originally Posted by c0rdawg
smokey do you just take other pieces of plugins and post them :roll: Anyways that had nothing to do with his post, and neither does this... sorry

Uh, I was just trying to help.

Xanimos 05-04-2006 01:05

Not a smart way of doing it.

wonsae 05-04-2006 10:02

so if i did
Code:
new answer = random_num(1,2000) if(answer == 1500){ }


how long would it take?

Xanimos 05-04-2006 10:12

Why do you need to know?
Less than a millisecond. These things go by very quickly.

Twilight Suzuka 05-04-2006 13:14

Actually, since the random number generator is the one put into C and C++ from either HL1's engine or from the STL or STD, its a simple mathamatical evaluation, meaning it takes as much as the function call to PAWN + a simple evaluation + the return value + a call to PAWN, which is significant, but no where near a whole milisecond; I'd put it at approximately 1000 - 10000 ( due to PAWN execution, not the actual generator) machine code instructions, which on a 1 gigahertz processor, is better approximated in billionths of a second, not millionths.

In simpler terms, it isn't expensive.

wonsae 05-04-2006 19:20

so if i did
Code:
new number = random_num(1,1000000) if(number == 1000000){ // code }

would it take atleast an hour or something?


All times are GMT -4. The time now is 04:59.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.