Gossamer Forum
Home : General : Perl Programming :

Making a random entry

Quote Reply
Making a random entry
Well what I am trying to do is pretty simple

What i want is say I have three varibles

$X $Y1 and $Y2

I want $X to equal either $Y1 or $Y2 randomly

what I tried to do was something like this

$X = 1 + int(rand(2));
$Y1 = 1;
$Y1 = "hello"
$Y2 = 2;
$Y2 = "goodbye";

Then I want the program to pring out the text that Y1 or Y2 equals but i am not sure how to make them equal to a intager and text

Like say if X = 1 it will print out hello if X = 2 I want it to print out goodbye

How would I go about doing this?

Oh also another thing I thought of that would have the same results just a different outcome

Is if i create a database with mysql with one table with two rows one column that first row is "hello" , second row is "goodbye"
How could i acces that in perl and print out at random the text in either row?

Last edited by:

zero87t: Jun 11, 2003, 7:45 PM
Quote Reply
Re: [zero87t] Making a random entry In reply to
well i messed around with it some more and i thought this would work

$X = int(rand(2));

if ($X = int(0))
$Y = "zero";

elsif ($X = int(1))
$Y = "one";

but it keeps outputting "one"

any help?