<?php 

$config = array(
    'copy' => '&copy; Lafac.ru',
    'billing_url' => '/billing',
    'coins_table' => 'money',
    'coins_name'  => array('монета', 'монеты', 'монет'),
    'disp_name'  => 'Монеты',
    'stavka' => array('1', '5', '25', '50', '100'),
    'step' => array('10', '8', '6', '4', '2'), 
    'url' => '/plugins/games/',
);

function get_code($count = 4) {
  $numbers = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
  $code = array_rand($numbers, $count);
  shuffle($code);
  return $code;
}

function get_num() 
{
  global $config;
  $line = '';
  $key = mt_rand(1111111111, 9999999999);
  $numbers = implode('|', get_code(4));
  
  return array('numbers' => $numbers, 'key' => $key, 'md5' => md5($line.$key));
}

function safe_num_search($search, $numbers) {
  $count = array();
  $count['par'] = count(array_intersect_assoc($search, $numbers));
  
  $i = array();
  foreach ($search AS $key => $value) {
    if (in_array($value, $numbers)) {
      $i[$value] = 1;
    }
  }
  $count['all'] = count($i);
  return $count;
}