Laravel Generate 4,6,8,10 Digit Unique Random Number Example

Laravel Generate 4,6,8,10 Digit Unique Random Number Example

Generate 4,6,8,10 digit unique random number in laravel. In this tutorial, you will learn how to generate 2,4,6,10,12 digit unique random number in PHP laravel.

Generate 4,6,8,10 Digit Unique Random Number in PHP Laravel

You can use the random_int() function to generate 2,4,6,10, digit unique random number in PHP Laravel.

First of all, you need to know about php random_int() function. As shown following:

rand_int() function

The PHP random_int() is inbuilt PHP function. Which is used to generate a random integer number.

Syntax

The basic syntax of random_int() function is following:

 random_int ( min,max);

Parameters of random_int() function

  • min:- This a first parameter of this function and it is optional. Specifies the minimum/smallest/lowest number to be returned. Default is 0
  • max:- This a second parameter of this function and it is also optional. Specifies the maximum/largest/highest number to be returned.

Generate 4 digit unique random number in laravel

You can use the following example to generate 4 digit unique random number in laravel:

<?php
  
namespace App\Http\Controllers;
  
class TestController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {
        $randomNumber = random_int(1000, 9999);
  
        dd($randomNumber);
    }
}

Generate 6 digit unique random number in laravel

You can use the following example to generate 6 digit unique random number in laravel:

<?php
  
namespace App\Http\Controllers;
  
class TestController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {
        $randomNumber = random_int(100000, 999999);
  
        dd($randomNumber);
    }
}

Recommended Laravel Posts

Recommended:-Laravel Try Catch

AuthorAdmin

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *