开发者

Making a dice in ruby language

开发者 https://www.devze.com 2023-04-09 06:36 出处:网络
Im coding a dice in ruby in which when i rolled it, it would either come up north south east or west.

Im coding a dice in ruby in which when i rolled it, it would either come up north south east or west.

what im having trouble with is when i roll it how do i tell it to return to 开发者_高级运维me one of these directions?

any help would be great.


Use Array.sample:

[ 'north', 'south', 'east', 'west' ].sample


It doesn't get much easier than %w(north south east west).sample (that's 1.9 method btw). Another thing that works in 1.8 and 1.9 is %w(north south east west)[rand(4)].

0

精彩评论

暂无评论...
验证码 换一张
取 消