mercredi 21 février 2018

How can I multiply 2 separate rand values within one argument in Ruby?

I would like to multiply 2 separate random numbers within an argument, to match the following (for example):

rand(1..6) + rand(1..6)

=>9 (result could be anything between 2-12)

I am in early stages of learning Ruby, so forgive me, but how do I achieve the same with multiplication? For example, the following will only multiply the same random number twice:

2 * rand(1..6)

=>2 (will only produce 2,4,6,etc)

Which is what you would expect. But how do I alter that statement to signify each rand should be a unique number that's being multiplied by the stated amount? Thank you.




Aucun commentaire:

Enregistrer un commentaire