This is the code that I currently use
val bytes = new Array[Byte](20)
scala.util.Random.nextBytes(bytes)
sendAndReceive(bytes)
Is there a way to turn that into a one-liner? For example, if it is an Integer array I can do
sendAndReceive(Array.fill(20){scala.util.Random.nextInt(9)}
Replacing nextInt
with nextBytes
does not work because nextBytes takes an Array[Byte]
as parameter, instead of returning a single Byte.