# Random string

**URL:** <https://www.ruby-forum.com/t/random-string/120753>\
**Category:** Ruby\
**Created:** [November 20, 2007, 11:12am UTC](https://www.ruby-forum.com/t/random-string/120753 "2007-11-20T11:12:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joakim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@joakim](https://www.ruby-forum.com/u/joakim)\
**Post date:** [November 20, 2007, 11:12am UTC](https://www.ruby-forum.com/t/random-string/120753/1 "2007-11-20T11:12:23Z")

</div>

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”?

---

<div class="post-metadata">

**Author:** ![joakim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dec6dc/32.png) [@joakim](https://www.ruby-forum.com/u/joakim)\
**Post date:** [November 20, 2007, 12:01pm UTC](https://www.ruby-forum.com/t/random-string/120753/2 "2007-11-20T12:01:25Z")

</div>

Joakim Olsson wrote:

> 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
