PHP to Ruby
Convert PHP code into Ruby!
-
array_rand
Posted on February 16th, 2010 1 commentThe array_rand() function in PHP randomly selects one or more elements from an array.
PHP
$users = array('john', 'jane', 'tim', 'alex'); $lucky_winner = array_rand($users); echo $lucky_winner; // alex
Ruby
users = [ 'john', 'jane', 'tim', 'alex' ]; lucky_winner = users[rand(users.length)]; puts lucky_winner; # => alex


