am-mokhtari/numeric-code
最新稳定版本:v2.0.1
Composer 安装命令:
composer require am-mokhtari/numeric-code
包简介
non-guessable numeric code generator
README 文档
README
Description
This package helps you create non-guessable and non-simple numeric codes.
Please note that this program only creates codes up to 8 digits!
The numbers created by this package meet the following conditions:
-
The repetition of each digit in the whole number cannot be more than twice.
- For example, the number
23242is not allowed because the digit2appears three times.
- For example, the number
-
Only one digit can appear twice in the whole number; the rest of the digits cannot be repeated.
- For example, the number
2332is not allowed.
- For example, the number
-
Only two consecutive digits are allowed.
- For example, the numbers
232or234are not allowed, but235is allowed.
- For example, the numbers
-
Consecutive numbers next to each other can appear only once in the whole number.
- For example, in the number
2354,2and3are next to each other and4and5are next to each other, which is not allowed!
- For example, in the number
How to Use
Install the package using the following command:
composer require am-mokhtari/numeric-code
Use the static function generate() and provide the desired format, like the code below:
$string_code = NumericCode::generate(5);
The output will be something like:
35634
Or
$string_code = NumericCode::generate(4);
The output will be something like:
3198
Speed Test
To test the execution time, create a php file and run this code:
This test generates 1000 numeric codes without failure. (100,000 have also been tested)
<?php require_once "./vendor/autoload.php"; use AmMokhtari\NumericCode\NumericCode; $start = microtime(true); for ($i = 0; $i < 1_000; $i++){ try { NumericCode::generate(8); // Generate an 8-digit code } catch (Exception $e) { echo "Error: " . $e->getMessage() . " <br>"; } } $end = microtime(true); $executionTime = $end - $start; echo "Execution Time: " . number_format($executionTime, 6) . " seconds <br>";
توضیحات
این پکیج به شما کمک میکند تا کد های عددی غیرقابل حدس و غیر ساده بسازید
توجه کنید که این برنامه فقط تا ۸ رقم کد ایجاد می کند!
اعدادی که توسط این پکیج ساخته میشوند شرط های زیر را پاس میکنند:
-
تعداد تکرار هر رقم در کل عدد نمیتواند بیش از دو مرتبه باشد.
- مثلا عدد
۲۳۲۴۲چون سه مرتبه عدد۲ظاهر شده مجاز نیست.
- مثلا عدد
-
فقط یک رقم میتواند در کل عدد دو مرتبه ظاهر شود و باقی ارقام مجاز به تکرار نیستند.
- مثلا عدد
۲۳۳۲مجاز نیست.
- مثلا عدد
-
فقط دو رقم متوالی در کنار هم مجاز هستند.
- مثلا عدد
۲۳۲یا۲۳۴مجاز نیستند ولی۲۳۵مجاز است
- مثلا عدد
-
اعداد متوالی در کنار هم فقط یکبار میتوانند در کل عدد ظاهر شوند
- مثلا، در عدد
۲۳۵۴چون۲و۳کنار هم و۴و۵کنار یکدیگر هستند و مجاز نیست!
- مثلا، در عدد
نحوه ی استفاده
پکیج را با دستور زیر نصب کنید
composer require https://packagist.org/packages/am-mokhtari/numeric_code
از تابع استاتیک generate() استفاده کنید و قالب مورد نظر را به آن بدهید، مثل کد زیر:
$string_code = NumericCode::generate(5);
خروجی چیزی شبیه به این خواهد بود:
35634
یا
$string_code = NumericCode::generate(4);
خروجی چیزی شبیه به این خواهد بود:
3198
تست سرعت
برای تست مدت زمان اجرا، یک فایل php ایجاد کنید و این کد را اجرا کنید:
این تست 1000 کد عددی را بدون شکست تولید می کند. (100000 هم تست شده)
<?php require_once "./vendor/autoload.php"; use AmMokhtari\NumericCode\NumericCode; $start = microtime(true); for ($i = 0; $i < 1_000; $i++){ try { NumericCode::generate(8); // Generate an 8-digit code } catch (Exception $e) { echo "Error: " . $e->getMessage() . " <br>"; } } $end = microtime(true); $executionTime = $end - $start; echo "Execution Time: " . number_format($executionTime, 6) . " seconds <br>";
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-03