Example #1
0
<html>
<head>
  <title>Check</title>
</head>
<body>



<?php 
include_once "../../connection/connect_new.php";
include_once "ajax_assist.php";
$school_id = 100;
$sql = "select TeacherId,Mobile,Name,TabUser,TabPass from teacher where SchoolId='{$school_id}' order by Name";
$res = mysql_query($sql) or die("Error in fetching from table" . mysql_error());
$tch_cnt = mysql_num_rows($res);
$rands = generate_tab_cred($tch_cnt);
$html = "";
$html = "<div class='row-fluid'>";
$html = "<table class='table table-striped tbl-disp-pass'>";
$html .= "<thead>\n            <th>Name</th>\n            <th>Username</th>\n            <th>Password</th>\n            </thead>";
$html .= "<tbody>";
$i = 0;
while ($row = mysql_fetch_array($res)) {
    $teacher_id = $row["TeacherId"];
    $tab_user = $row["TabUser"];
    $tab_pass = $row["TabPass"];
    $is_cls_tch = is_class_tch($teacher_id);
    $is_sub_tch = is_sub_tch($teacher_id);
    $mobile = $row["Mobile"];
    $name = $row["Name"];
    // if($tab_user<9999 && $tab_user>1000){
Example #2
0
}
function generate_tab_cred($no_of_tchs)
{
    $curr_max = 3700;
    $map_nums = create_map();
    $start = 0;
    $rand_nos = array();
    while ($start <= $curr_max && $start < $no_of_tchs) {
        $rand_index = rand(0, $curr_max);
        array_push($rand_nos, $map_nums[$rand_index]);
        // changing range
        $map_nums[$rand_index] = $map_nums[$curr_max];
        $curr_max -= 1;
        $start++;
    }
    return $rand_nos;
}
$no_of_tchs = $argv[1];
$rands = generate_tab_cred($no_of_tchs);
print_r($rands);
########################## code ends ############################
// validation and testing
function array_has_dupes($array)
{
    return count($array) !== count(array_unique($array));
}
if (array_has_dupes($rands)) {
    print_r("duplicates");
} else {
    print_r("no duplicates");
}