Generating random numbers and keeping the highest

Hi guys! I've been trying to tinker with ruby lately and came across this obstacle.

I'm trying to make a dice roller for a tabletop rpg I play with my friends.

The game uses a 'roll x dice, keep y highest' system and I'm trying to reproduce this but have been failing miserably! So for example, a character rolls 6d10 and keeps the 3 highest, which will then be summed and compared to a target number.

Can anyone shed a light please? much appreciated!
I don't know Ruby but I do know programming. I would do a for loop 10 times. In the loop, I would generate a random number between 1 and 6, and push each value to an array. Then sink sort (sort ascending) so the highest values are on the bottom. Hopefully Ruby has a built in method for sorting arrays. If not, you should be able to find some code on the Internet for either sink sort or bubble sort. Bubble sort sorts the opposite way (highest on top). Then pop the last 3 array elements and add them up. If you do a bubble sort, you'll have to get the first 3 array elements. That should do what you need.
Here's a non sort method (you will still need to store the numbers in an array).
Example:
Code:
test = [4, 6, 2, 6, 8]
p test.max(3){|x, b| x <=> b}
#=> [8, 6, 6]

Original thread: https://forums.rpgmakerweb.com/threads/generating-random-numbers-and-keeping-the-highest.80683/