PHPackages                             am-mokhtari/numeric-code - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. am-mokhtari/numeric-code

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

am-mokhtari/numeric-code
========================

non-guessable numeric code generator

v2.0.1(1y ago)06MITPHPPHP ^8.2

Since Aug 14Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/am-mokhtari/numeric-code)[ Packagist](https://packagist.org/packages/am-mokhtari/numeric-code)[ RSS](/packages/am-mokhtari-numeric-code/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)DependenciesVersions (5)Used By (0)

[![Imgur](https://camo.githubusercontent.com/b22829b65253b44993e374c7dacd2e295fd989a5b4816002aa9c5261705a79b0/68747470733a2f2f692e696d6775722e636f6d2f597279777437392e6a7067)](https://camo.githubusercontent.com/b22829b65253b44993e374c7dacd2e295fd989a5b4816002aa9c5261705a79b0/68747470733a2f2f692e696d6775722e636f6d2f597279777437392e6a7067)

Description
===========

[](#description)

### This package helps you create non-guessable and non-simple numeric codes.

[](#this-package-helps-you-create-non-guessable-and-non-simple-numeric-codes)

### *Please note that this program only creates codes up to `8` digits!*

[](#please-note-that-this-program-only-creates-codes-up-to-8-digits)

### The numbers created by this package meet the following conditions:

[](#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 `23242` is not allowed because the digit `2` appears three times.
- Only one digit can appear twice in the whole number; the rest of the digits cannot be repeated.

    - For example, the number `2332` is not allowed.
- Only two consecutive digits are allowed.

    - For example, the numbers `232` or `234` are not allowed, but `235` is allowed.
- Consecutive numbers next to each other can appear only once in the whole number.

    - For example, in the number `2354`, `2` and `3` are next to each other and `4` and `5` are next to each other, which is not allowed!

---

How to Use
==========

[](#how-to-use)

### Install the package using the following command:

[](#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
============

[](#speed-test)

#### To test the execution time, create a php file and run this code:

[](#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)

```
