Jump to content

[SOLVED] Seeding Random "rand()" function


Demonic

Recommended Posts

Does Seeding the random function make the random number not repeat?  Why do you seed the rand() function?

 

function make_password()
{
	$pass = "";
	$chars = array(
		"1","2","3","4","5","6","7","8","9","0",
		"a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J",
		"k","K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T",
		"u","U","v","V","w","W","x","X","y","Y","z","Z");

	$count = count($chars) - 1;

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

	for($i = 0; $i < 8; $i++)
	{
		$pass .= $chars[rand(0, $count)];
	}

	return($pass);
}

 

Example function from ipb 1.3

all the function does is make a random 8 charecter/number

and ads the varable $pass to the beging........... 

 

<?php
$pass="redarrow";

function pass($pass) {
$chars = array(
"1","2","3","4","5","6","7","8","9","0",
"a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J",
"k","K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T",
"u","U","v","V","w","W","x","X","y","Y","z","Z");
$count = count($chars) - 1;
srand((double)microtime()*1000000);
for($i = 0; $i < 8; $i++)
{
$pass .= $chars[rand(0, $count)];
}
return($pass);
}

echo pass($pass)

?>

all the function does is make a random 8 charecter/number

and ads the varable $pass to the beging........... 

I never asked what teh function does, because its quite obvious what it does.

 

Anyways thanks, so seeding random numbers are deprecate.

 

solved..

so this example is better then using mt_rand......

 

dont no

 

<?php
$pass="redarrow";

function pass($pass) {
$chars = array(
"1","2","3","4","5","6","7","8","9","0",
"a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J",
"k","K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T",
"u","U","v","V","w","W","x","X","y","Y","z","Z");

$count = count($chars) - 1;

for($i = 0; $i < 8; $i++)
{
$pass .= $chars[mt_rand(0, $count)];
}
return($pass);
}

echo pass($pass)

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.