From: Heesob Park Date: 2007-11-27T19:03:35+09:00 Subject: Re: Most elegant way to do this? Hi, unknown wrote: > Are there any more elegant, concise, pithy, and more Rubyish ways of > doing this? > > def roll(number_of_dice) > sum = 0 > number_of_dice.times do > sum += rand(5).next > end > sum > end > > Thanks in advance! If you want the dice number, you should use rand(6). How about this: def roll(n) eval('+rand(6)+1'*n) end Regards, Park Heesob -- Posted via http://www.ruby-forum.com/.