|
Posted by Jon Slaughter on 06/07/07 17:23
"Aerik" <asylvan@gmail.com> wrote in message
news:1181233787.529402.108340@i38g2000prf.googlegroups.com...
> Jon,
>
> What are you trying to accomplish? Do you have a list of functions,
> and you want to call each one if the probability of it being called is
> above a certain threshold? If so, a very simple approach might be to
> assign the probabilities and functions to an array.
>
> See if this is what you're trying to do, or perhaps clarify it to me/
> us:
>
> $funcary[] = array('probability'=>.75, 'funcname'=>'function1');
> $funcary[] = array('probability'=>.47, 'funcname'=>'function2');
> $funcary[] = array('probability'=>.99, 'funcname'=>'function3');
>
> $curprob = rand(0,100)/100;
>
> foreach($funcary as $afunc=>$ary){
> if ($afunc['probability'] < $curprob) $afunc['funcname']();
> }
>
> Where 'function1' etc. are the names of your functions. I didn't test
> this at all, fyi, but I think it should work.
>
> Aerik
>
No, that is my application but what I'm trying to do is in some way assign
the probability to the function that is inline with the function definition.
If, say, I have to create 100 of these functions then then I want to
minimize the amount of excess code just to add the probability part.
I can automatically include the functions because they are in a class and I
use get_class_methods to get them... but this just gives me the functions
and in not the probabilities.
For your method you have to know the function name and you have to add them
to the array manually. With my method I do it automatically but I cannot
easily handle the probabilities. (right now I just use 1 as default so I can
get on with the other parts.
If there was some other function such as get_function_attributes for
example, or get_function_vars which returns the variables used in a
function(or static vars) then I could extract the probabilities
automatically. Of course there isn't anything like this.
I suppose I could open up the file as a text file and parse it myself but
this is more work that I'd rather not do unless someone as an easy way and
it also seems kinda inefficient.
Jon
Navigation:
[Reply to this message]
|