Faker offers a couple of methods that let you replace placeholders in a given string with random characters:

  • lexify - takes given string and replaces ? with random letters
  • asciify - takes given string and replaces * with random ascii characters
  • numerify - takes given string and replaces # with random digits
  • bothify - combines the lexify and numerify

You could try to use one of them, depending on the requirements you have for that random string you need. asciify uses the largest set of characters as replacement so using that one makes most sense.

The following will give you a random string of 20 ascii characters:

$faker->asciify('********************')
Answer from jedrzej.kurylo on Stack Overflow
🌐
FakerPHP
fakerphp.org › formatters › numbers-and-strings
Numbers and Strings - FakerPHP / Faker
Generates a random float. Optionally it's possible to specify the amount of decimals. The second and third parameters optionally specify a lower and upper bound respectively. echo $faker->randomFloat(); // 12.9830, 2193.1232312, 102.12 echo ...
🌐
GitHub
github.com › fzaninotto › Faker
GitHub - fzaninotto/Faker: Faker is a PHP library that generates fake data for you · GitHub
<?php // Generates a random AVS13/AHV13 social security number echo $faker->avs13; // "756.1234.5678.97" OR echo $faker->ahv13; // "756.1234.5678.97"
Starred by 26.7K users
Forked by 3.6K users
Languages   PHP
🌐
Shortcode
shortcode.dev › laravel › faker.html
Laravel cheatsheet > Faker
#laravel#db · Reference: https://github.com/fzaninotto/Faker · $faker = Faker\Factory::create(); $faker->name; // First and second name $faker->randomDigit; // A random number $faker->word; // A single word $faker->sentence; // A sentence $faker->unique()->word; // A single unique word ...
🌐
GitHub
github.com › fzaninotto › Faker › issues › 1512
$faker->unique()->numberBetween(1, 20) · Issue #1512 · fzaninotto/Faker
June 21, 2018 - I'm using Laravel and I have 2 factory states: user and post. I generate 20 users, and 50 posts. Now the interesting part, here are the 2 states, redundent code removed: User: factory(App\Photo::Class, 20)->states('user')->create(); $factory->state(App\Photo::class,'user', function (Faker $faker) { return ([ 'imageable_id' => $faker->unique()->numberBetween(1,20), 'imageable_type' => 'App\User' ]); });
Author   datner
🌐
Laravelia
laravelia.com › post › laravel-faker-random-10-digit-number-example
Laravel Faker Random 10 Digit Number Example
December 13, 2022 - laravelia.com · 2025 Copyright | All Rights Reserved. Privacy Policy
Find elsewhere
🌐
OneLinerHub
onelinerhub.com › php-faker › how-do-i-generate-a-random-number-between-two-numbers-using-laravel-faker
Php Faker: How do I generate a random number between two numbers using Laravel Faker? - OneLinerHub
For example, to generate a random number between 1 and 10, you can use the following code: $randomNumber = Faker::numberBetween(1, 10); echo $randomNumber;
🌐
Laravel Daily
laraveldaily.com › post › generate-random-strings-laravel-helper-methods
Generate Random Strings with Laravel: Helper Methods
May 22, 2024 - The randomNumber() method could be used to generate a random number. ... Link to the documentation. If you want to hide some characters in the generated string, you can do it with str($string)->mask(). Let's combine it with Faker from above.
🌐
FakerPHP
fakerphp.org
FakerPHP / Faker
// unique() forces providers to return unique values $values = []; for ($i = 0; $i < 10; $i++) { // get a random digit, but always a new one, to avoid duplicates $values []= $faker->unique()->randomDigit(); } print_r($values); // [4, 1, 8, 5, ...
🌐
GitHub
github.com › fzaninotto › Faker › issues › 471
generate unique random number? · Issue #471 · fzaninotto/Faker
December 1, 2014 - $faker->unique()->randomNumber($nbDigits = 8); 👍React with 👍7winex01, splinter89, wilsonpinto, elshobokshy, mehranhadidi and 2 more · No one assigned · No labels · No labels · No projects · No milestone ·
Author   mansouralex
🌐
Fwhy
fwhy.github.io › faker-docs › formatters › base › random_number.html
randomNumber | FakerPHP非公式リファレンス
November 22, 2023 - 返される整数の桁数を1から9で指定します。 nullを指定した場合、randomDigitNotNull()で生成されたランダムな値になります。 · trueにした場合、返り値が正確に$nbDigits桁になります。 · $strictに真偽値以外を渡した場合、または$maxにmt_getrandmax()より大きい値を渡した場合はInvalidArgumentExceptionが発生します。 · >>> Faker\Factory::create('ja_JP')->randomNumber() => 17 >>> Faker\Factory::create()->radomNumber(9) => 735949189 >>> Faker\Factory::create()->randomNumber(5, true) => 18904 ·
🌐
ZetCode
zetcode.com › php › faker
PHP Faker - generating fake data in PHP with Faker package
February 16, 2025 - "\n"; dump($faker->shuffle([1, 2, 3, 4, 5, 6])); The example generates random digits, integers, and floats. It also randomly shuffles array values. $ php numbers.php 6 6 3654715 614 4164 12.29093 2347 array:6 [ 0 => 3 1 => 6 2 => 2 3 => 5 4 => 1 5 => 4 ]
🌐
Laravel
laravel.com › docs › 7.x › database-testing
Database Testing | Laravel 7.x - The clean stack for Artisans and agents
Within the Closure, which serves as the factory definition, you may return the default test values of all attributes on the model. The Closure will receive an instance of the Faker PHP library, which allows you to conveniently generate various kinds of random data for testing.