LinuxGuruz
Toll Free Numbers
Custom Search
MAIN MENU
Main Page
IT Jobs
IPTABLES
Linux Forum
HTML Forum
PHP Forum
MySQL Forum
Linux FAQ
Linux Articles
About Us
Privacy Policy

ADD TO FAVORITES


MARC

Mailing list ARChives
- Search by -
 Subjects
 Authors
 Bodies





FOLDOC

Computing Dictionary






Cheap UK Web Hosting Provider

Cheap Dedicated Servers UK

Cheap Linux VPS Hosting UK

Cheap Cloud Hosting UK



Icons
Icons


free brochure template
Free Brochure Template

Web Hosting

Domain Names

Web Design

Reseller Hosting

Registro de Dominios

Reseller Hosting


Toll Free Number for $2.00/Month!!!

Toll Free Number for $2.00/Month!!!
Random String Functions

Title:       Random String Functions
Contributor: Jeffrey Paul (aka sneak)
Last Update: Friday March 31 00:22 EDT 2000


<?php

/*********************************************************************
 *  string randstring(int $length)                                   *
 *********************************************************************
 *  This function returns a random string of length $length.  It     *
 *  uses ascii values 48-57, 65-90, and 97-122 (all inclusive), and  *
 *  will accept values of 1 to 65535 for length.  It's output        *
 *  contains a-z, A-Z, and 0-9.  This is suitable for some password  *
 *  applications and such.  (no whitespace)                          *
 *********************************************************************
 *  Sample:                                                          *
 *  6rI9m664D8cjF6i3l2R9mb21WO387VK9q04K8VGEqm906bbPTBedx1SEof4d5pcD *
 *  PI0lm9uesw4F5cv8sjS5XNi58t7NCh48Zk9x9P95Lp2cHOl8NA611y5TCWxI2hIO *
 *  bue099apD1kkhG03eh1B7F02gVEImuHb457XNGakp8I7k248WEG1xaa5kxZA64s1 *
 *  7xU0nW7HF41Vz5y9un8VfM1r6RFWr5uAf1yg2zRB8F45fI1sns6cN770MxG4uYoM *
 *  7EmbgoTD4GbsFC7oSW20Rsm2179HWp6k90vQhT3eb6uIqRJqcze78V7Qfig5KyZh *
 *********************************************************************/
function randstring ($length) {

if(!ereg("^[0-9]+$", $length))
        return(-1);

if($length < 1 || $length > 65536)
        return(-1);

srand((double)microtime()*1000000);

$string = '';

while(strlen($string) != $length)  {
        $type = rand(1,3);
        if($type == 1) $string = $string . chr(rand(48,57));
        if($type == 2) $string = $string . chr(rand(65,90));
        if($type == 3) $string = $string . chr(rand(97,122));
}

return($string);
}
/*********************************************************************/




/**********************************************************************
 *  string goodrandstring(int $length)                                *
 **********************************************************************
 *  This function returns a random string of length $length.  It uses *
 *  ascii values 33 to 126 inclusive, and will accept values of 1 to  *
 *  65535 for length.  Sample output follows.  It's good for          *
 *  creating secure passwords.  It does not output spaces, tabs, or   *
 *  returns (all easily printable non-high ascii minus whitespace).   *
 **********************************************************************
 *  Sample:                                                           *
 *                                                                    *
 * /^z>QY"TnE&Ic0bB3R5>8U<`Jepmuc*[Zx>E*1@{(%f~m *
 * 5XK(D\\b?a)@nsrpsMZ+vFl;vz=5V&H;/*B\\89g7]q4[B)nlF|vMBp&9E *
 * "+y^wk"<EI.nET?^%Y^4l1iIG}3f&h]{+QBDJI,/rHs{:?N&a *
 * mp;r$+0CE-|A_\\a,FQuso$_;iN<d5|T>(_$36%"5~4_XmB|oJrjY\\ *
 * w<T]j6ux%'K(=y?p1|t+Xa4s:=?'_5L7otxtCB1S>>$}Nh^P4eta:     *
 * <L}2YJho"iL?1QKb#Ten5BmO5pqU2/{_NWp^Kum6wqb]inQ?eDPTu5.u7] *
 * iTHn*`kz/=}ePHB                                                    *
 **********************************************************************/
function goodrandstring ($length) {

if(!ereg("^[0-9]+$", $length))
        return(-1);

if($length < 1 || $length > 65536)
        return(-1);

srand((double)microtime()*1000000);

$string = '';

while(strlen($string) != $length)  {
        $string = $string . chr(rand(33,126));
        }

return($string);
}
/*********************************************************************/




/**********************************************************************
 *  string bestrandstring(int $length)                                *
 **********************************************************************
 *  This function returns a random string of length $length.  It uses *
 *  all ascii values from 1 to 255 (no null bytes).  It can deal with *
 *  length values from 1 to 65535.  Don't use this for passwords or   *
 *  anything like that, as most of these will break terminals and     *
 *  browsers and the such.  There is no sample because if you think   *
 *  you need one this function isn't for you.                         *
 **********************************************************************/
function bestrandstring ($length) {

if(!ereg("^[0-9]+$", $length))
        return(-1);

if($length < 1 || $length > 65536)
        return(-1);

srand((double)microtime()*1000000);

$string = '';

while(strlen($string) != $length)  {
        $string = $string . chr(rand(1,255));
        }

return($string);
}
/*********************************************************************/

?>


        Anyone who wishes to make additions or changes to this
PHP Tip email them to webmaster@linuxguruz.org

        This document is Copyright (c) 1999, 2000 by LinuxGuruz

Return to the LinuxGuruz PHP Tutorials Page
Return to the LinuxGuruz Main Page


www.PHP.net Search Engine


Restrict the search to:
Copyright © 1999, 2000 The PHP Development Team.
Submit a PHP Tutorial

Title:

Contributor:

IRC NICK: (optional)

E-Mail Address: (optional)

Tutorial:

Return to the LinuxGuruz PHP Tutorials Page
Return to the LinuxGuruz Main Page

RESOURCE LINKS
Linux
Apache
HTML
PHP
MySQL
PostgreSQL
Oracle
CGI
Perl
Java
C/C++
Bash
Tcl
Networking
Security
ISP
IRC
Xwindow
Laptop
Graphics
Hardware
Reference
Misc

Broadband


filing cabinet

  • Buy Batteries for Laptops and Cameras
  • Notebooks
  • Michael Fertik
  • Reputation Defender

  • XP Style Icons
    XP Style Icons


    Network Certification


    Network Security


    Wireless Networking


    Canadian
    Web Hosting in Canada


    Drummer Portal


    Mending Media

    The Path Of
    Most Resistance


    Toll Free Number for $2.00/Month!!!

    Toll Free Number for $2.00/Month!!!


    Linux

    The Distributions





    Linux

    The Software





    Linux

    The News




    webmaster@linuxguruz.com
    Copyright © 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 and 2009 by LinuxGuruz