Random string

J

Joakim Olsson

lala = 'Koko'
tjucka = 'tero'
asdf = 'jfsd'

puts <?????????????????>

What should I have instead of <?????????????????> for the program to
puts one random string either "Koko", "tero" or "jfsd"?
 
L

Lee Jarvis

Joakim said:
What should I have instead of <?????????????????> for the program to
puts one random string either "Koko", "tero" or "jfsd"?

If I understand you right, you just want to print one of them variables
randomly. Without any relationship between them you cant do it (unless
there were some way of collecting all method variables).

You could always use an array, perhaps.

puts ['Koko', 'tero', 'jfsd'][rand(3)]

Regards,
Lee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,270
Messages
2,571,353
Members
48,038
Latest member
HunterDela

Latest Threads

Top