jeudi 24 août 2017

How should I create an Array of random integers in Ruby?

This Python code creates a list of count random integers, each between 1 and 6 (inclusive):

[random.randrange(1, 7) for _ in range(count)]

Given that Ruby does not have Python's comprehensions, what would be an idiomatic way to produce a similar Array in Ruby?




Aucun commentaire:

Enregistrer un commentaire