Skip to content

Instantly share code, notes, and snippets.

@opnchaudhary
Last active April 18, 2018 03:52
Show Gist options
  • Save opnchaudhary/4995012 to your computer and use it in GitHub Desktop.
Save opnchaudhary/4995012 to your computer and use it in GitHub Desktop.
Random String Generator : Helper File for Codeigniter
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// ------------------------------------------------------------------------
/**
* Random String Generator : Helper File for Codeigniter
*
* @author Paras Nath Chaudhary
* @link https://gist.github.com/opnchaudhary/4995012
*
*/
// ------------------------------------------------------------------------
/*
Documentation:
=============
1.
$this->load->helper('rand_helper');
$randomString=generateRandomString();
echo $randomString;
2.
$this->load->helper('rand_helper');
$randomString=generateRandomString(14);
echo $randomString;
*/
if ( ! function_exists('generateRandomString'))
{
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
}
/* End of file rand_helper.php */
@sasi1346862
Copy link

Hiiii.....I need help..... I want last three digit number (RNG)...I HAVE PERVIOUS NUMBERS IF ANYONE CAN HELP ME.........PLEASE...... Waiting for the response.......

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