日曜日, 12月 27, 2015

Scala - 乱数生成プロバイダを用いるstream


    val r = new Random(System.currentTimeMillis())
    def rand(max:Int):Stream[Int] = Stream.cons(r.nextInt(max), rand(max))
    rand(100) take 10 foreach println
    // assign index starting from 1. zipWithIndex()'s index starts from 0
    rand(50) take 5 zip(Stream from 1) foreach println

0 件のコメント: