intellex/generator

v1.0.1 2020-05-05 16:29 UTC

This package is auto-updated.

Last update: 2024-06-06 01:29:55 UTC


README

Examples and full list of supported generators below.

Image:
  • Image URL generator from Pixabay service (requires free API key).
Core:
  • Boolean generator with selectable chance of true.
  • Get a number in range, with or without Gaussian distribution.
  • Random item from weighted array, allows you to manipulate chances.
  • Random date time from a period, in any format.
Text and HTML:
  • Generate random strings from custom or predefined pools of characters.
  • Lorem ipsum text generator that supports: single word, variable length sentences, full paragraphs and complete articles.
  • Full HTML generator for decorated sentences, paragraphs or full-out article with images (requires free Pixabay API key).
Bonus
  • Generate a GPS coordinate, that is a maximum of meters away from any center you choose.
  • A hardcoded generator that always returns the same results, just for good measure :)

Examples

Tip: After cloning, point browser to tests/index.php to see every possible result.

Image:

echo '<img src="' . (new PixabayImageURLGen($pixabayAPIKey, [ 'q' => 'kitten' ], PixabayImageURLGen::SIZE_960))->gen() . '" />';

GPS location within 3000 meters from the city centre of Amsterdam, Netherlands:

(new \Intellex\Generator\Plus\GpsLocationGen(52.3677607, 4.8785829, 3000));

Boolean with 50% chance of true:

(new BooleanGen())->gen();

Boolean with 80% chance of true:

(new BooleanGen(0.8))->gen();

Random number in range of 50 - 250:

(new NumericGen(50, 250))->gen();

Random number of mean 38 and mean 5 (Gaussian distribution):

(new GaussianDistributionGen(38, 4))->gen();

Random item from array:

(new ItemGen([ 1, 2, 3, 5, 7, 11 ]))->gen();

Random weighted item from array, where is 2 times more likely than B and 6 times more likely than C:

(new WeightedItemGen([ 'A' => 6, 'B' => 3, 'C' => 1 ]))->gen();

Full HTML article, with images:

(new HTMLArticleGen(true, $pixabayAPIKey))->gen();

List of all generators

Core:

  • BooleanGen generates a boolean value, with the ability to give more chances to any of the results.
  • NumericGen generates a random number in a specified range.
  • GaussianDistributionGen uses a normal distribution to pick a random value in a range.
  • HardcodedGen uses the value supplied in the constructor as a generated value, every time.
  • ItemGen picks an item from the pool, where every item has the same change of being picked.
  • WeightedItemGen picks a random item from the pool, with the ability to influence the change of picking for each item.

Bonus:

  • GpsLocationGen generates a GPS location, within a supplied radius of a given central point. Output format is ,, with a maximum of 6 decimal digit precision.
  • PixabayImageURLGen generates a URL to a random image on the Pixabay free image service, using their API.

Time:

  • TimestampGen generates a random timestamp in a given range.
  • DateTimeGen generates a random date in YYYY-MM-DD hh:mm:ss format.
  • DateGen generates a random date in YYYY-MM-DD format.
  • TimeGen generates a time in 24h format.

Strings and text:

  • StringGen generates a random string.
  • WordGen generates a single word, from a predefined "lorem ipsum" dictionary.
  • SentenceGenerator generates a dummy sentence.
  • ParagraphGen generates a random paragraph from random sentences.
  • ArticleGen generates a random article form random paragraphs.

HTML:

  • HTMLSentenceGen generates a random sentences with random HTML tags, such as b, strong, em, etc...
  • HTMLParagraphGen generates a valid HTML paragraph.
  • HTMLSectionGen generates an HTML header with random paragraphs.
  • HTMLArticleGen generates a complete HTML article.

To do

  1. Testing of the results.
  2. Better implementation of the WeightedItemGen.
  3. Setters for all constructor parameters for all generators.
  4. New generators.

Licence

MIT License

Copyright (c) 2019 Intellex

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Credits

Script has been written by the Intellex team.