src/bbn/db.php
public function random_value($col, $table){
    $val = null;
    if ( ($tab = $this->modelize($table)) && isset($tab['fields'][$col]) ){
      foreach ( $tab['keys'] as $key => $cfg ){
        if (
          $cfg['unique'] &&
          !empty($cfg['ref_column']) &&
          (\count($cfg['columns']) === 1) &&
          ($col === $cfg['columns'][0])
        ){
          return ($num = $this->count($cfg['ref_column'])) ? $this->select_one([
            'tables' [$cfg['ref_table']],
            'fields' => [$cfg['ref_column']],
            'start' => random_int(0, $num - 1)
          ]) : null;
        }
      }
      switch ( $tab['fields'][$col]['type'] ){
        case 'int':
          if ( ($tab['fields'][$col]['maxlength'] === 1) && !$tab['fields'][$col]['signed'] ){
            $val = microtime(true) % 2 === 0 ? 1 : 0;
          }
          else {
            $max = 10 ** $tab['fields'][$col]['maxlength'] - 1;
            if ( $max > mt_getrandmax() ){
              $max = mt_getrandmax();
            }
            if ( $tab['fields'][$col]['signed'] ){
              $max /= 2;
            }
            $min = $tab['fields'][$col]['signed'] ? -$max : 0;
            $val = random_int($min, $max);
          }
          break;
        case 'float':
        case 'double':
        case 'decimal':
          break;
        case 'varchar':
          break;
        case 'text':
          break;
        case 'date':
          break;
        case 'datetime':
          break;
        case 'timestamp':
          break;
        case 'time':
          break;
        case 'year':
          break;
        case 'blob':
          break;
        case 'binary':
          break;
        case 'varbinary':
          break;
        case 'enum':
          break;
      }
    }
    return $val;
  }
public function random_value($col, $table){
    $val = null;
    if ( ($tab = $this->modelize($table)) && isset($tab['fields'][$col]) ){
      foreach ( $tab['keys'] as $key => $cfg ){
        if (
          $cfg['unique'] &&
          !empty($cfg['ref_column']) &&
          (\count($cfg['columns']) === 1) &&
          ($col === $cfg['columns'][0])
        ){
          return ($num = $this->count($cfg['ref_column'])) ? $this->select_one([
            'tables' [$cfg['ref_table']],
            'fields' => [$cfg['ref_column']],
            'start' => random_int(0, $num - 1)
          ]) : null;
        }
      }
      switch ( $tab['fields'][$col]['type'] ){
        case 'int':
          if ( ($tab['fields'][$col]['maxlength'] === 1) && !$tab['fields'][$col]['signed'] ){
            $val = microtime(true) % 2 === 0 ? 1 : 0;
          }
          else {
            $max = 10 ** $tab['fields'][$col]['maxlength'] - 1;
            if ( $max > mt_getrandmax() ){
              $max = mt_getrandmax();
            }
            if ( $tab['fields'][$col]['signed'] ){
              $max /= 2;
            }
            $min = $tab['fields'][$col]['signed'] ? -$max : 0;
            $val = random_int($min, $max);
          }
          break;
        case 'float':
        case 'double':
        case 'decimal':
          break;
        case 'varchar':
          break;
        case 'text':
          break;
        case 'date':
          break;
        case 'datetime':
          break;
        case 'timestamp':
          break;
        case 'time':
          break;
        case 'year':
          break;
        case 'blob':
          break;
        case 'binary':
          break;
        case 'varbinary':
          break;
        case 'enum':
          break;
      }
    }
    return $val;
  }
public function random_value ( $ col , $ table ) { $ val = null ; if ( ( $ tab = $ this -> modelize ( $ table ) ) && isset ( $ tab [ 'fields' ] [ $ col ] ) ) { foreach ( $ tab [ 'keys' ] as $ key => $ cfg ) { if ( $ cfg [ 'unique' ] && ! empty ( $ cfg [ 'ref_column' ] ) && ( \ count ( $ cfg [ 'columns' ] ) === 1 ) && ( $ col === $ cfg [ 'columns' ] [ 0 ] ) ) { return ( $ num = $ this -> count ( $ cfg [ 'ref_column' ] ) ) ? $ this -> select_one ( [ 'tables' [ $ cfg [ 'ref_table' ] ] , 'fields' => [ $ cfg [ 'ref_column' ] ] , 'start' => random_int ( 0 , $ num - 1 ) ] ) : null ; } } switch ( $ tab [ 'fields' ] [ $ col ] [ 'type' ] ) { case 'int' : if ( ( $ tab [ 'fields' ] [ $ col ] [ 'maxlength' ] === 1 ) && ! $ tab [ 'fields' ] [ $ col ] [ 'signed' ] ) { $ val = microtime ( true ) % 2 === 0 ? 1 : 0 ; } else { $ max = 10 ** $ tab [ 'fields' ] [ $ col ] [ 'maxlength' ] - 1 ; if ( $ max > mt_getrandmax ( ) ) { $ max = mt_getrandmax ( ) ; } if ( $ tab [ 'fields' ] [ $ col ] [ 'signed' ] ) { $ max /= 2 ; } $ min = $ tab [ 'fields' ] [ $ col ] [ 'signed' ] ? - $ max : 0 ; $ val = random_int ( $ min , $ max ) ; } break ; case 'float' : case 'double' : case 'decimal' : break ; case 'varchar' : break ; case 'text' : break ; case 'date' : break ; case 'datetime' : break ; case 'timestamp' : break ; case 'time' : break ; case 'year' : break ; case 'blob' : break ; case 'binary' : break ; case 'varbinary' : break ; case 'enum' : break ; } } return $ val ; }
Returns a random value fitting the requested column's type

@todo This great function has to be done properly
@param $col
@param $table
@return mixed
Returns a random value fitting the requested column s type