← Back to Gists

Array#sample

📝 Ruby
moniquediaz119
moniquediaz119 · Level 10 ·

Returns a random element (or multiple random elements if given an argument) from an array.

Ruby
arr = [10, 20, 30, 40, 50]
puts arr.sample
puts arr.sample(3).inspect

Comments

No comments yet. Start the discussion.