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

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Vue JS, Angular JS, React Js, WordPress, and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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