title: Insert a random int that does not exist in Dtabase not working?
body: <p>mt_rand() and random_int() both are generate only one numbe and insert it in database where the number is already exist. I want to clear that , I want to insert a random number that is not exist in database.</p>
  <p>I took this code from <a href="https://stackoverflow.com/questions/28524290/how-to-generate-unique-random-value-for-each-user-in-laravel-and-add-it-to-datab">here</a></p>
  <p>In my case in laravel 8, the code looks like below</p>
  <pre><code>public function generateProductCode() {
      $number = mt_rand(1000000000, 9999999999); 
  
      // call the same function if the barcode exists in Dtabase already
      if ($this-&gt;productCodeExists($number)) {
          return $this-&gt;generateProductCode();
      }
  
      // otherwise, it's valid and can be used
      return $number;
  }
  
  public function productCodeExists($number) {
      // query the database and return a boolean
      // for instance, it might look like this in Laravel
      return Product::where('product_code', $number)-&gt;exists();
  }
  </code></pre>
  <p>The model name is Product and DB table name is products. 'product_code' is the column where I want to do this query.
  In store function where I Call generateProductCode() function, it looks like below</p>
  <pre><code>public function store(Request $request)
  {
      $product = new Product;
      //Generate a Product key
      $product-&gt;product_code = $this-&gt;generateProductCode();
      $product-&gt;save();
   }
  </code></pre>
  <p>It returns all time only one numbers that is <em><strong>2147483647</strong></em> .
  <a href="https://i.stack.imgur.com/f1XBL.png" rel="nofollow noreferrer">Photo is here</a>
  What is the wrong? What is the perfect query to check exist so that it returns another that is not exist in the database.</p>