Page 1 of 1

Avatar generation - no code, just thinking

Posted: Thu Aug 05, 2004 5:28 pm
by Calimero
This is the idea to create an avatar, so just to consult with experts>

If I create a list of 10, 20, 30 weird words and use random function - I get what I want, BUT...

I was wondering to do it this way, so just to see if this is not taking too much resources.

I declare an array A - Z a-z 0-9
and use 3 random functons to get $a, $b, $c from the same array
then I join $a.$b.$c and echo them as a new variable.

What is faster and more reliable. Somehow I think that the secong method is better because number of possible combinations software can generate is over 300.000, I would never write so much combinations (even no more than 100) for the first method)

And I heard of Image as avatar - but I read doc's and didn't got a thing - so if someone has a sample code (that is willing to share) I would be more than greatefull.

Any suggestions, thanks !

Posted: Thu Aug 05, 2004 5:57 pm
by hawleyjr
Here are some recursive functions I wrote some time ago. You may want to play with something like this:

Code: Select all

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

$array_len = count($lowerAlpha);
runReq3($lowerAlpha,0,$array_len);


function runReq4($a,$val,$array_len){
	
	for($x=0;$x<$array_len;$x++){
		for($y=0;$y<$array_len;$y++){
			for($z=0;$z<$array_len;$z++){	
				//echo md5($a[$val].''.$a[$x].''.$a[$y].''.$a[$z]);
				echo $a[$val].''.$a[$x].''.$a[$y].''.$a[$z];
				//echo '<BR>';				
				echo "\r";	
			}
		}	
	}	
	$val++;
	if($val<$array_len){
		runReq4($a,$val,$array_len);	
	}
}
function runReq3($a,$val,$array_len){
	
	for($x=0;$x<$array_len;$x++){
		for($y=0;$y<$array_len;$y++){

				//echo md5($a[$val].''.$a[$x].''.$a[$y]);
				echo $a[$val].''.$a[$x].''.$a[$y];
				//echo '<BR>';				
				echo "\r";	
		}	
	}	
	$val++;
	if($val<$array_len){
		runReq3($a,$val,$array_len);	
	}
}
function runReq2($a,$val,$array_len){
	
	for($x=0;$x<$array_len;$x++){

				//echo md5($a[$val].''.$a[$x]);
				echo $a[$val].''.$a[$x];
				//echo '<BR>';				
				echo "\r";	

	}	
	$val++;
	if($val<$array_len){
		runReq2($a,$val,$array_len);	
	}
}



echo '<HR>end of file<hr>';
?>
oh, btw / runReq4() takes up a ton of server memory and can crash a browser session.