random string

This is a discussion on random string within the PHP General forums, part of the PHP Programming Forums category; Hi, I want to randomise a string $myrandom = rand("ross", "andrea"); echo $myrandom; I know this ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-17-2006
Ross
 
Posts: n/a
Default random string


Hi,

I want to randomise a string

$myrandom = rand("ross", "andrea");

echo $myrandom;


I know this doesn't work but is there a built in function to do this?


R.
Reply With Quote
  #2 (permalink)  
Old 10-17-2006
NurAzije
 
Posts: n/a
Default Re: random string

Use this:
srand((float) microtime() * 10000000);
$array_name = array("rose","andrea");
$myrandom = array_rand($array_name);
echo $myrandom[0];
For unique randomization, or you can also use
srand((float)microtime() * 1000000);
shuffle($array_name);
echo $myrandom[0];
------------------------------------------------------------------------------------------
For php/ajax/javascript tutorials and tips, visit me on my blog at
http://www.nurazije.co.nr

Reply With Quote
  #3 (permalink)  
Old 10-17-2006
Richard Lynch
 
Posts: n/a
Default Re: [PHP] random string

On Tue, October 17, 2006 7:30 am, Ross wrote:
> I want to randomise a string
>
> $myrandom = rand("ross", "andrea");
>
> echo $myrandom;
>
> I know this doesn't work but is there a built in function to do this?


I'm not real clear on what "this" is...

Choose a string at random from an array?

$possibles = array('ross', 'andrea');
shuffle($possibles);
echo $possibles[0];


Or are you trying to compose a new string of randomly-selected
characters of a bunch of other strings?

Some combination of these functions might be in the recipe:
http://php.net/mt_rand
http://php.net/shuffle
http://php.net/explode

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 03:39 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0