David and Sharon Phillips
2/11/2007 7:47:00 AM
try
example= %w[one two three cat dog cow table]
puts example[rand(example.size)]
Cheers,
Dave
On 11/02/2007, at 6:25 PM, woodyee wrote:
> Hi! I'm trying to write a program that will print out a different
> string each time it's run from a list of strings.
>
> For example:
>
> example = ['one', 'two', 'three']
> # sort them somehow
> # 'two' prints out as the output, for example
> # run it again and a different string prints out
>
> Make sense? I've tried srand & rand but can't do this with strings. Do
> I need to forget the arrays and try something else? I've looked at the
> Pickaxe book and Ruby Cookbook but can't find anything. Thanks!
>
>