How to generate a list of random numbers?

后端 未结 3 601
青春惊慌失措
青春惊慌失措 2020-12-28 11:27

This might be the least important Scala question ever, but it\'s bothering me. How would I generate a list of n random number. What I have so far:

def n_ra         


        
3条回答
  •  [愿得一人]
    2020-12-28 12:08

    You can either use Don's solution or:

    Seq.fill(n)(Random.nextInt)
    

    Note that you don't need to create a new Random object, you can use the default companion object Random, as stated above.

提交回复
热议问题