Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,458 members, 7,819,669 topics. Date: Monday, 06 May 2024 at 08:25 PM

Introducing Randgen, Codeigniter Library For Generating... - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Introducing Randgen, Codeigniter Library For Generating... (1064 Views)

How Can I Build An E-library For School? / New Bucketjs Library For Javascript Released / Codeigniter Tutorial For Beginners- Explanation With Text,pics And Video (2) (3) (4)

(1) (Reply) (Go Down)

Introducing Randgen, Codeigniter Library For Generating... by Nobody: 1:47pm On Aug 25, 2016
CodeIgniter random string generator library. This library can be used for generating ticket ID's, user ID's or anything that needs randomness :-).

Requirements

PHP >=5.2.4

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:

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
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

Call the generate() method. The generate() method accepts two arguments: Length (Int) and Type ('alpha'|'numeric'|'alpha-numeric').
Arguments | Description | Value
Length ---- The length of the string to be generated ---- alpha, numeric, alpha-numeric
Type ---- The string type to be generated. ---- Int

The 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:

<?php
// Random string of 100 characters using the default combination
$randString = $this->rand_gen->generate( 100 ) ;
echo $randString ;

// Random string of 30 characters containing only alphabets
$randAlphaString = $this->rand_gen->generate( 30, 'alpha' ) ;
echo $randAlphaString ;

// Random string of 250 characters containing only numbers
$randNumString = $this->rand_gen->generate( 250, 'numeric' ) ;
echo $randNumString ;

// Random string of 50 characters containing only alphabets and numbers
$randAlphanumString = $this->rand_gen->generate( 50, 'alpha-numeric' ) ;
echo $randAlphanumString ;
?>

Contributing

Fork it!
Create your feature branch: git checkout -b my-new-feature
Commit your changes: git commit -am 'Add some feature'
Push to the branch: git push origin my-new-feature
Submit a pull request cheesy

License

MIT License

2 Likes

Re: Introducing Randgen, Codeigniter Library For Generating... by Codenister: 8:47pm On Aug 25, 2016
Cool, will try it out very soon.

Your effort is laudable

1 Like

Re: Introducing Randgen, Codeigniter Library For Generating... by Nobody: 9:42pm On Aug 25, 2016
Codenister:
Cool, will try it out very soon.
Your effort is laudable
Glad you're giving it a try..
Re: Introducing Randgen, Codeigniter Library For Generating... by Cooldude68(m): 9:49pm On Aug 25, 2016
DanielTheGeek:
CodeIgniter random string generator library. This library can be used for generating ticket ID's, user ID's or anything that needs randomness :-).

Requirements



Installation via Composer

Install Composer to your project root:



Add a composer.json file to your project:

Run the Composer installer:



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:

And you're good to go.
Usage
Loading the library:

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



Generating random string

Call the generate() method. The generate() method accepts two arguments: Length (Int) and Type ('alpha'|'numeric'|'alpha-numeric').
Arguments | Description | Value
Length ---- The length of the string to be generated ---- alpha, numeric, alpha-numeric
Type ---- The string type to be generated. ---- Int

The 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:



Contributing

Fork it!
Create your feature branch: git checkout -b my-new-feature
Commit your changes: git commit -am 'Add some feature'
Push to the branch: git push origin my-new-feature
Submit a pull request cheesy

License

MIT License
I really appreciate your post. I'm a developer as well, but I'll like to learn more from u. Can I av your whatsapp contact?
Re: Introducing Randgen, Codeigniter Library For Generating... by Nobody: 9:53pm On Aug 25, 2016
Cooldude68:

I really appreciate your post. I'm a developer as well, but I'll like to learn more from u. Can I av your whatsapp contact?

.Hope to learn from you too.

1 Like

Re: Introducing Randgen, Codeigniter Library For Generating... by Codenister: 8:05am On Aug 26, 2016
DanielTheGeek:


Glad you're giving it a try..
Do you have a link to on git??
Re: Introducing Randgen, Codeigniter Library For Generating... by Nobody: 5:50pm On Aug 26, 2016

(1) (Reply)

MS Project 2016 For Mac / [help] Need Senior Programmers To Explain These Things For Me. / Drive UNLIMITED Genuine Real Traffic To Your Website

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 19
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.