mardi 21 avril 2015

Generate random numbers and pass to method in Groovy

I have select(int a, int b, int c) method and I want to pass it 3 random generated values and select(). So I do:

public void select() {
        Random random = new Random()
        def values= []
        (1..3).each {
            values<< random.nextInt(100 + 1)
        }
        select(values[0], values[1], values[2])
    }

But it is Groovy code and I want to make it shorter. How can I do that can I do something like(I can't but how to modify it to run):

public void select() {
              select((1..3).each {
            values<< random.nextInt(100 + 1)
        }
    }




Aucun commentaire:

Enregistrer un commentaire