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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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? |