473,320 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Generating random text

hey guys....
i need php to generate random text...
thanks in advance...
tarun.
Sep 20 '07 #1
2 1579
brettl
41
I've used these two function before to generate random passwords. I'm not sure if this is what you're looking for but it may put you in the right direction.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. function Random_Text($length) {
  3.     srand(date("s"));
  4.     $possible_charactors = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  5.     $string = "";
  6.     while(strlen($string)<$length) {
  7.         $string .= substr($possible_charactors, rand()%(strlen($possible_charactors)),1);
  8.     }
  9.     return($string);
  10. }
  11.  
  12. echo 'random text: ';
  13. echo Random_Text(8); 
  14. echo '<br/>';
  15.  
  16. function ramdomword($length){ 
  17.  
  18.     srand((double)microtime()*1000000); 
  19.  
  20.     $vowels = array("a", "e", "i", "o", "u"); 
  21.     $cons = array("b", "c", "d", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "u", "v", "w", "tr", 
  22.     "cr", "br", "fr", "th", "dr", "ch", "ph", "wr", "st", "sp", "sw", "pr", "sl", "cl"); 
  23.  
  24.     $num_vowels = count($vowels); 
  25.     $num_cons = count($cons); 
  26.  
  27.     for($i = 0; $i < $length; $i++){ 
  28.         $password .= $cons[rand(0, $num_cons - 1)] . $vowels[rand(0, $num_vowels - 1)]; 
  29.     } 
  30.  
  31.     return substr($password, 0, $length); 
  32. }  
  33.  
  34. echo '<br/>';
  35. echo 'random word(almost): ';
  36. echo ramdomword(10); 
  37. ?>
  38.  
Sep 20 '07 #2
pbmods
5,821 Expert 4TB
Changed thread title to better describe the problem (did you know that threads whose titles contain phrases such as, 'urgent' actually get FEWER responses?).
Sep 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Simon Wittber | last post by:
I'm building a web application using sqlalchemy in my db layer. Some of the tables require single integer primary keys which might be exposed in some parts of the web interface. If users can...
2
by: randomcz | last post by:
hi, i need help with generating random numbers; The task is to generate hundreds of random vectors, like 1,3,5,6,7 2,4,5,4,8 ... I used the current time as the random seed, but it turns...
0
SammyB
by: SammyB | last post by:
These are some "random" thoughts about generating random numbers in Visual Basic. Wikipedia will give a better introduction than I, see http://en.wikipedia.org/wiki/Random_number_generator. ...
6
by: Mike P | last post by:
I am generating 12 random strings and my code works fine when I step through, but when I then let it run without stepping through and populate a listbox with the array I am building, I get the same...
1
by: Krimp | last post by:
I pulled this code from Vbasic.net or generating random passwords. I want to know how I can set up so that each time the page is refreshed a new password is generated without having to fill in the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.