Jump to content
CA3LE

Missing results

Recommended Posts

If you've seen intermittent test results missing it was most likely an issue with logging on TMN's end.

 

A few members have reported this and I've seen it happen on my end.  What was happening?  There are so many results logged in the database that test ID's were being assigned that were already logged.  In that case TMN won't overwrite the previous result... it just won't log a result.  You'd still see your results but they wouldn't be recorded.

 

TMN results will now check the test ID to make sure it hasn't been used before attempting to log the result.  It repeats this (a limited number of attempts) until it finds a testID that hasn't been used. 

 

The likelihood that it won't find an ID after those attempts is extremely low.  But if you ever see it happen again let me know and I can adjust it.

 

 

Share this post


Link to post
Share on other sites

This was happening far too frequently.  There are many millions of results in the database but not nearly enough to account for the frequency this was happening.  Even if there were 10,000X as many results in the database, I wouldn't expect to see this.

 

Upon a closer look I realized that the way I was generating test ID's can give bias to certain characters.  It's only pseudo random.

 

The naive approach

$password = "";
$possible = "~-_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
$possible = str_shuffle($possible);
$i = 0; 
while ($i < 9) { 

  $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);

  if (!strstr($password, $char)) { 
    $password .= $char;
    $i++;
  }

 

This uses a random integer to select from a set of N elements.  Unless the number of possible random integers is a multiple of N, some characters will have a higher chance of being picked than others.

 

Screen Shot 2018-08-03 at 6.48.33 PM.png

 

Using newer php functions I'm generating it this way now.

function RandomToken($length = 9){
    if(!isset($length) || intval($length) <= 8 ){
      $length = 9;
    }
    if (function_exists('random_bytes')) {
        return bin2hex(random_bytes($length));
    }
    if (function_exists('mcrypt_create_iv')) {
        return bin2hex(mcrypt_create_iv($length, MCRYPT_DEV_URANDOM));
    } 
    if (function_exists('openssl_random_pseudo_bytes')) {
        return bin2hex(openssl_random_pseudo_bytes($length));
    }
}

function Salt(){
	$replace = array("+" => "~", "/" => "-");
    return substr(strtr(base64_encode(hex2bin(RandomToken(9))), $replace), 0, 9);
}

$password = Salt();

 

Still room for improvement.  I think I might make the string initially larger and then scramble the base64 string before it gets clipped... I think that will improve it even more.  Or maybe I find a better way.

 

I feel there will be less of a chance of even being assigned an already logged testID.  And if it does happen, as I previously mentioned you'll be assigned a different ID.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...