| |
|
Welcome to AstaHost - Dear Guest | |
Replying to Php Random Text Generating
Topic Summary
Posted 01 June 2010 - 01:13 AM
Posted 17 May 2010 - 10:23 AM
<?php/** * @author Praateek * @copyright 2010 */$randcheck = rand(0, 4); if ($randcheck == 0) { $custom = chr(ord("a") + rand(0, 25)) . Rand(10, 99) . Chr(ord("a") + rand(0, 25)) . rand(10, 99); } elseif ($randcheck == 1) { $custom = rand(10, 99) . Chr(ord("a") + rand(0, 25)) . Rand(10, 99) . Chr(ord("a") + rand(0, 25)); } elseif ($randcheck == 2) { $custom = chr(ord("a") + rand(0, 25)) . Chr(ord("a") + rand(0, 25)) . Rand(10, 99) . rand(10, 99); } elseif ($randcheck == 3) { $custom = rand(10, 99) . Rand(10, 99) . Chr(ord("a") + rand(0, 25)) . Chr(ord("a") + rand(0, 25)); } elseif ($randcheck == 4) { $custom = rand(10, 99) . Chr(ord("a") + rand(0, 25)) . Chr(ord("a") + rand(0, 25)) . rand(10, 99); } echo $custom;?>
HannahI
Posted 23 February 2010 - 10:22 PM
Quatrux
Posted 23 February 2010 - 07:13 AM
abcdef1234567890
where with my method and 8ennett method you can include anything you want, even #$%^ symbols, which can be good for a CAPTCHA or for a SMS code or for any code which needs to be short and have a lot of different variations to not generate the same.
Those long codes which are lets say 16 letters are good for generating confirmation codes, where you don't really care about it, those kind of codes usually are copied and pasted or clicked on.
HannahI
Posted 21 February 2010 - 09:40 PM
8ennett
Posted 29 January 2010 - 04:20 PM
$alphanum = "abcdefghijkmnpqrstuvwxyz23456789"; $rand = substr(str_shuffle($alphanum), 0, 5); // 5 Being the amount of letters/numbers are select from the variable alphanum
And if you want letters and numbers to have a chance of being repeated:
$alphanum = "abcdefghijkmnpqrstuvwxyz23456789";
$inc = 1;
while ($inc < 5){
$alphanum = $alphanum.'abcdefghijkmnpqrstuvwxyz23456789';
$inc++;
}
$rand = substr(str_shuffle($alphanum), 0, 5); // 5 Being the amount of letters/numbers are select from the variable alphanum And finally for a random length text string with possible repeated letters or numbers:
$alphanum = "abcdefghijkmnpqrstuvwxyz23456789";
$inc = 1;
while ($inc < 5){
$alphanum = $alphanum.'abcdefghijkmnpqrstuvwxyz23456789';
$inc++;
}
$rand = substr(str_shuffle($alphanum), 0, rand(3,10)); // 3 Being the minimum amound of letters returned and 10 being the maximumPosted 29 January 2010 - 07:59 AM
I want to a making a word from group of the character.Eg. Opinion is a correct word from the group of character ionnipo(generate a group of the word in php from 7 character)
-reply by musavvir
Quatrux
Posted 30 October 2009 - 01:06 PM
function gen_chars($length = 6) {
// Available characters
$chars = '0123456789abcdefghjkmnoprstvwxyz';
$Code = '';
// Generate code
for ($i = 0; $i < $length; ++$i)
{
$Code .= substr($chars, (((int) mt_rand(0,strlen($chars))) - 1),1);
}
return $Code;
}
// Usage
$var = gen_chars(12);
echo $var;In the function variable $chars = '..'; I did not include all the letters, because I use this function for sending SMS code to activate some feature on a site and some letters does not feet, due to they look similar, like l can look like 1 and etc. if they are one to another, of course if you'll add all the alphabet and maybe even other symbols and even uppercase letters you'll get a much bigger probability for it to be different for example looping it million times and of course making more than 6 or 12 characters/length will have more different variations.
Posted 08 September 2009 - 08:57 PM
Ya know what you could just do is be sneaky and do this.
$ranNum = rand(100,9999).'-'.Rand(10000,999999);
$hexRan = md5($ranNum );
ThisConverts it to a MD5 Hash and since its random it doesn't reallyMatter. Store it in the DB and you should be good. Of course this codeIs only good if you want to have letters and numbers in the string. IfYou're going for JUST text, well then I would suggest doing somethingLike what is described above.
marijnnn
Posted 18 February 2005 - 09:13 AM
a,b,c,d,... ,A,B,C,D,... 1,2,3,...
let's say you get a table of 80 fields.
then you could just pick a random field
you could do this in various way: just rand(0,80)
if you have doubts about the randomness of rand, you could rand a random times and then start picking your letters
$i = rand(0,20);
for ($j=0; $j<$i;$j++) rand(0,80);
for ($i=0; $i<$passlenght;$i++)
$pw =$pw.$array[rand(0,80)];
or you could use srand
or you could go like rand(0,846854354)%80
anything that makes you feel safer



