https://github.com/jonasraoni/probability-randomizer
Generates randomized data based on fixed probabilities.
https://github.com/jonasraoni/probability-randomizer
chance php probability probability-distribution random random-generation
Last synced: about 1 year ago
JSON representation
Generates randomized data based on fixed probabilities.
- Host: GitHub
- URL: https://github.com/jonasraoni/probability-randomizer
- Owner: jonasraoni
- License: mit
- Created: 2017-10-26T07:37:32.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-26T07:45:13.000Z (over 8 years ago)
- Last Synced: 2025-01-25T14:43:07.370Z (over 1 year ago)
- Topics: chance, php, probability, probability-distribution, random, random-generation
- Language: PHP
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Probability Randomizer
Generates randomized data based on fixed probabilities
1. Include the main class source file:
```php
require_once 'ProbabilityRandomizer.php';
```
2. Instanciate the class
```php
$prExample = new ProbabilityRandomizer;
```
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.
```php
$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.
```php
for( $x=10; $x--; print $prExample->get() . '
' );
```
Sample output:
>I have more chances than everybody :]
I have more chances than everybody :]
I have more chances than everybody :]
I'm difficult to appear...
I have good chances
I have more chances than everybody :]
I have more chances than everybody :]
I have more chances than everybody :]
I have good chances
I have good chances