src/bbn/db.php
public function new_id($table, int $min = 1){
    $tab = $this->modelize($table);
    if ( \count($tab['keys']['PRIMARY']['columns']) !== 1 ){
      die("Error! Unique numeric primary key doesn't exist");
    }
    if (
      ($id_field = $tab['keys']['PRIMARY']['columns'][0]) &&
      ($maxlength = $tab['fields'][$id_field]['maxlength'] )&&
      ($maxlength > 1)
    ){
      $max = (10 ** $maxlength) - 1;
      if ( $max >= mt_getrandmax() ){
        $max = mt_getrandmax();
      }
      if ( ($max > $min) && ($table = $this->tfn($table, true)) ){
        $i = 0;
        do {
          $id = random_int($min, $max);
          /** @todo */
          /*
          if ( strpos($tab['fields'][$id_field]['type'], 'char') !== false ){
            $id = substr(md5('bbn'.$id), 0, random_int(1, 10 ** $maxlength));
          }
          */
          $i++;
        }
        while ( ($i < 100) && $this->select($table, [$id_field], [$id_field => $id]) );
        return $id;
      }
    }
    return null;
  }
public function new_id($table, int $min = 1){
    $tab = $this->modelize($table);
    if ( \count($tab['keys']['PRIMARY']['columns']) !== 1 ){
      die("Error! Unique numeric primary key doesn't exist");
    }
    if (
      ($id_field = $tab['keys']['PRIMARY']['columns'][0]) &&
      ($maxlength = $tab['fields'][$id_field]['maxlength'] )&&
      ($maxlength > 1)
    ){
      $max = (10 ** $maxlength) - 1;
      if ( $max >= mt_getrandmax() ){
        $max = mt_getrandmax();
      }
      if ( ($max > $min) && ($table = $this->tfn($table, true)) ){
        $i = 0;
        do {
          $id = random_int($min, $max);
          /** @todo */
          /*
          if ( strpos($tab['fields'][$id_field]['type'], 'char') !== false ){
            $id = substr(md5('bbn'.$id), 0, random_int(1, 10 ** $maxlength));
          }
          */
          $i++;
        }
        while ( ($i < 100) && $this->select($table, [$id_field], [$id_field => $id]) );
        return $id;
      }
    }
    return null;
  }
public function new_id ( $ table , int $ min = 1 ) { $ tab = $ this -> modelize ( $ table ) ; if ( \ count ( $ tab [ 'keys' ] [ 'PRIMARY' ] [ 'columns' ] ) !== 1 ) { die ( "Error! Unique numeric primary key doesn't exist" ) ; } if ( ( $ id_field = $ tab [ 'keys' ] [ 'PRIMARY' ] [ 'columns' ] [ 0 ] ) && ( $ maxlength = $ tab [ 'fields' ] [ $ id_field ] [ 'maxlength' ] ) && ( $ maxlength > 1 ) ) { $ max = ( 10 ** $ maxlength ) - 1 ; if ( $ max >= mt_getrandmax ( ) ) { $ max = mt_getrandmax ( ) ; } if ( ( $ max > $ min ) && ( $ table = $ this -> tfn ( $ table , true ) ) ) { $ i = 0 ; do { $ id = random_int ( $ min , $ max ) ; /** @todo */ /*
          if ( strpos($tab['fields'][$id_field]['type'], 'char') !== false ){
            $id = substr(md5('bbn'.$id), 0, random_int(1, 10 ** $maxlength));
          }
          */ $ i ++ ; } while ( ( $ i < 100 ) && $ this -> select ( $ table , [ $ id_field ] , [ $ id_field => $ id ] ) ) ; return $ id ; } } return null ; }
Generate a new casual id based on the max number of characters of id's column structure in the given table

```php
\bbn\x::dump($db->new_id('table_users', 18));
// (int) 69991701
```

@todo Either get rid of th efunction or include the UID types
@param null|string $table The table's name.
@param int $min
@return mixed
Generate a new casual id based on the max number of characters of id s column structure in the given table