This class is very simple to be used. Follow step-by-step instructions:
1. Include the main class source file:
include( 'lib.probabilityRandom.php' );
2. Instanciate the class
$prExample = new probabilityRandom;
3. Add items to the class using the "add( data, probability )" method.
The first parameter can be any data defined by you, the second parameter
defines the probability of this "data" appear in the results.
$prExample->add( "I have more chances than everybody :]", 20 );
$prExample->add( "I have good chances", 10 );
$prExample->add( "I'm difficult to appear...", 1 );
4. At this point, everything is ready. Just call the "get" method. It will
choose one between the previously added items relying on the probability
level and will return the "data" assigned to it.
|