Raised This Month: $ Target: $400
 0% 

how to select random variable?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kiki33hun
Veteran Member
Join Date: Jul 2011
Location: Magyarország
Old 08-24-2012 , 06:48   how to select random variable?
Reply With Quote #1

how to select random variable?

Like:
new variable1;
new variable2;
new variable3;


I should pick one of these up to my dating!
Like:

random_function(variable1,variable2,variable3 ), and return variable on random! Example return: variable3

Thanx, sorry my english xD
__________________
kiki33hun is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 08-24-2012 , 07:00   Re: how to select random variable?
Reply With Quote #2

random_function(variable1, variable2, variable3) {
switch (random_num(0,2)) {
case 0: return variable1
case 1: return variable2
case 2: return variable3
}
}

or just have those variables as an array

new variable[3]
variable[random_num(0,2)] //random value from array

Last edited by jimaway; 08-24-2012 at 07:02.
jimaway is offline
kiki33hun
Veteran Member
Join Date: Jul 2011
Location: Magyarország
Old 08-24-2012 , 07:07   Re: how to select random variable?
Reply With Quote #3

Lol, thanx
__________________
kiki33hun is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 08-24-2012 , 10:59   Re: how to select random variable?
Reply With Quote #4

Can you use like enum?

for example:
PHP Code:
enum _:Variables {
    
Variable1,
    
Variable2,
    
Variable3,
    
Variable4

and then just use
PHP Code:
switch(random(3)) {
    case 
0Variable1
    
case 1Variable2
    
case 2Variable3
    
case 3Variable4

Isn't this possible aswell?
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-24-2012 , 14:56   Re: how to select random variable?
Reply With Quote #5

It would be better to use an array, because it is shorter code and easier to extend.

Code:
new variable1; new variable2; new variable3; random_variable() {     switch(random(3))     {         case 1: return variable2;         case 2: return variable3;     }     return variable1; }
Code:
new variables[3]; random_variable() {     return variables[random(sizeof(variables))]; }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-24-2012 , 19:03   Re: how to select random variable?
Reply With Quote #6

Quote:
Originally Posted by Napoleon_be View Post
Can you use like enum?

for example:
PHP Code:
enum _:Variables {
    
Variable1,
    
Variable2,
    
Variable3,
    
Variable4

and then just use
PHP Code:
switch(random(3)) {
    case 
0Variable1
    
case 1Variable2
    
case 2Variable3
    
case 3Variable4

Isn't this possible aswell?
No. You don't do anything in your code.
__________________

Last edited by fysiks; 08-24-2012 at 19:04.
fysiks is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 08-24-2012 , 20:17   Re: how to select random variable?
Reply With Quote #7

Quote:
Originally Posted by fysiks View Post
No. You don't do anything in your code.
It's not a full code, just trying if this would work or not.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 08-24-2012 , 20:59   Re: how to select random variable?
Reply With Quote #8

No it won't unless the values are constants.
Backstabnoob is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:48.


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