Re: [scala-functional] Immediate Requirement - Scala Developer
Bangalore? No thanks, I'm in the USA. On Sun, Mar 17, 2019 at 7:28 PM Deepak Panda wrote: > There is a requirement for pure scala developer in my project at ATOS > bangalore. Candidate should have genuine realtime experience and should > join within 15 days. Experience required 5+ years. If anyone interested > Please ping me in personal. Basic Knowledge of Hadoop and spark is an > advantage. You can share your resume, name, days within u can join to > deepakpand...@gmail.com > > -- > You received this message because you are subscribed to the Google Groups > "scala-functional" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to scala-functional+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Adam Mackler -- You received this message because you are subscribed to the Google Groups "scala-functional" group. To unsubscribe from this group and stop receiving emails from it, send an email to scala-functional+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[scala-functional] Re: lazy val memoization
The value cached is defined inside the definition of the method func(), so everytime you invoke func() it defines a new local Int named cached. Change your code to this: def func(i: => Int): Unit = { lazy val cached = { println("Calculating") i * i } println(cached) println(cached) println(cached) } and you will see that it prints "Calculating" only once each time you invoke func(), even though func() is now accessing cached three times. -- You received this message because you are subscribed to the Google Groups "scala-functional" group. To unsubscribe from this group and stop receiving emails from it, send an email to scala-functional+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[scala-functional] EXERCISE 6.2: generating a random Double from a random Int
Exercise 6.2 on page 83: *Write a function to generate a Double between 0 and 1 , not including 1.* The given hint and answer indicate generating a non-negative Int and then dividing it by the one more than the maximum possible Int value. Maybe I'm missing something, but it seems to me that since a Double is represented using 64 bits and an Int 32, that using the amount of randomness in an Int to generate a random Double will mean that the results will be unevenly distributed, perhaps with possible values of the Double never returned. Here's what I came up with: def double(rng: RNG): (Double, RNG) = { val (int1, rng2) = rng.nextInt val (int2, rng3) = rng2.nextInt val long = (int1.toLong << 32) | int2// this is a random Long val nnLong = if (long < 0) -(long + 1) else long // non-negative random Long val rLong = -(nnLong.toDouble / Long.MinValue) // random double (rLong, rng3) } I generate two random integers, convert one to a Long and bit-shift it 32 bits to the left and then OR it with the other Int. This should give me a random Long. Then I make it non-negative, divide it by the minimum Long value, and negate that. Intuitively this seems to me that it would give a more even distribution since there are extra bits of randomness from the second Int. Is my thinking correct? Is this worse or better than the answer given in the book? -- You received this message because you are subscribed to the Google Groups "scala-functional" group. To unsubscribe from this group and stop receiving emails from it, send an email to scala-functional+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.