Skip to content

Instantly share code, notes, and snippets.

@yakirh
Created August 6, 2013 09:42
Show Gist options
  • Select an option

  • Save yakirh/6163177 to your computer and use it in GitHub Desktop.

Select an option

Save yakirh/6163177 to your computer and use it in GitHub Desktop.
Testing random alphanumeric token exercise
<?php
try
{
$length = 8;
$start_time = microtime(TRUE);
for ($i = 1; $i <= 10000; $i++)
{
$token = $this->rand_alphanumeric($length);
if (strlen($token) !== $length)
throw new Exception('Token "'.$token.'" length is invalid. token length is '.(strlen($token)).' instead of '.$length);
if ( ! preg_match('#[0-9]#',$token))
throw new Exception('Token "'.$token.'" is invalid. token must contain at least 1 digit');
if ( ! preg_match('#[a-zA-Z]#',$token))
throw new Exception('Token "'.$token.'" is invalid. token must contain at least 1 letter');
}
$execution_time = (float) number_format(microtime(TRUE)-$start_time, 5);
die("Success! ~~ Execution Time: $execution_time seconds");
}
catch (Exception $e)
{
die($e->getMessage());
}
@yakirh
Copy link
Copy Markdown
Author

yakirh commented Aug 6, 2013

Replace "$this->rand_alphanumeric(" with your function.

@rafi
Copy link
Copy Markdown

rafi commented Aug 6, 2013

COol!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment