> On Jun 7, David Gilden said:
> 
> >@colors = qw[ #F0F8FF #00FFFF #7FFFD4 #F0FFFF #F5F5DC #FFE4C4 #4169E1
> >#8B4513 #FA8072 #F4A460 #2E8B57 #A0522D ];
> >
> >
> ># choose a color!
> >$color_choice1 = rand $#colors;

On Thursday, June 7, 2001 at 3:40 PM, [EMAIL PROTECTED] (Jeff 'japhy' Pinyan) wrote:

> 
> You're never going to select "#A0522D" this way -- you need to use
> rand(@colors), not rand($#colors).  Read the rand() docs -- it returns x
> such that 0 <= x < ARG.
> 
> I would splice() the array after I get the first color from it.
> 
>   $first = splice @colors, rand(@colors), 1;
>   $second = splice @colors, rand(@colors), 1;
> 
> That way, I always get two different colors.  

Thanks Jeff, 
I will have to read up on Splice, 

The way I am using this to generate html where each line is in a different color,

@colors = qw[ #F0F8FF #00FFFF #7FFFD4 #F0FFFF #F5F5DC #FFE4C4 #4169E1 #8B4513 #FA8072 
#F4A460 #2E8B57 #A0522D ];


$color_choice1 = rand ($#colors + 1);  #thanks for pointing this out!

This code is in a cgi that when called appends some text to a file and then exits. 

So now that I think about it, I will need the last $color_choice to be stored between 
cgi calls!

Dave 

*====================================================*
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/                   *  
*   Resources, Recordings, Instruments & More!       *
*====================================================*

Reply via email to