PHPackages                             danielthegeek/rand-gen - 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. danielthegeek/rand-gen

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

danielthegeek/rand-gen
======================

Random string generator for the CodeIgniter framework

213[1 issues](https://github.com/DanielTheGeek/rand-gen/issues)PHP

Since Aug 25Pushed 9y ago1 watchersCompare

[ Source](https://github.com/DanielTheGeek/rand-gen)[ Packagist](https://packagist.org/packages/danielthegeek/rand-gen)[ RSS](/packages/danielthegeek-rand-gen/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

RandGen v1.0.0
==============

[](#randgen-v100)

CodeIgniter random string generator library. This library can be used for generating ticket ID's, user ID's or anything that needs randomness :-).

Requirements
------------

[](#requirements)

- PHP &gt;=5.2.4

Installation via [Composer](http://getcomposer.org/)
----------------------------------------------------

[](#installation-via-composer)

Install Composer to your project root:

```
$ curl -sS https://getcomposer.org/installer | php
```

Add a `composer.json` file to your project:

```
{
  "require": {
    "danielthegeek/rand-gen": "dev-master"
  }
}
```

#### Run the Composer installer:

[](#run-the-composer-installer)

```
php composer.phar install
```

Copy the `Rand_gen.php` file from `path/to/project/vendor/danielthegeek/rand-gen/src` to your CI library folder normally located at `path/to/project/application/libraries`. For example:

```
$ cd /var/www/html/example-project
$ cp vendor/danielthegeek/rand-gen/src/Rand_gen.php application/libraries
```

And you're good to go.

Usage
-----

[](#usage)

### Loading the library:

[](#loading-the-library)

```
public function myFunction()
{
  $this->load->library('rand_gen');
}
```

or auto load the library if you plan on using it frequently by editing `application/config/autoload.php`

```
$autoload['libraries'] = array('rand_gen');
```

### Generating random string

[](#generating-random-string)

Call the `generate()` method. The `generate()` method accepts two arguments: Length (Int) and Type ('alpha'|'numeric'|'alpha-numeric').

ArgumentsDescriptionValueLengthThe length of the string to be generatedalpha, numeric, alpha-numericTypeThe string type to be generated.IntThe string type value can be:

- `alpha` - Generates a string that contains only alphabets,
- `numeric` - Generates a string that contains only numbers or
- `alpha-numeric` - Generates a string that contains a combination of alphabets and numbers If a string type is not defined, the default combination will be used. For example:

```
