php-fakerHow can I generate a random float using PHP Faker?
Using PHP Faker library, you can generate a random float with the following code:
<?php
require_once 'vendor/autoload.php';
$faker = Faker\Factory::create();
echo $faker->randomFloat(2, 0, 100);
The output of the above code will be a random float with 2 digits after the decimal point, ranging from 0 to 100.
The code consists of the following parts:
require_once 'vendor/autoload.php';
- This imports the Faker library.$faker = Faker\Factory::create();
- This creates an instance of the Faker library.echo $faker->randomFloat(2, 0, 100);
- This generates a random float with 2 digits after the decimal point, ranging from 0 to 100.
For more information, you can refer to the Faker documentation.
More of Php Faker
- How can I generate a fake timestamp using PHP Faker?
- How do I use the Laravel Faker numerify function?
- How do I generate JSON data using PHP Faker?
- How do I generate a zip file using PHP Faker?
- How do I generate a fake year in Laravel using Faker?
- How do I generate a valid VAT number using Laravel Faker?
- How can I generate a zip code using Laravel Faker?
- How can I generate fake data in XLSX format using PHP Faker?
- How do I check which version of Laravel Faker I am using?
- How do I use PHP Faker to generate XML data?
See more codes...