When re-coding an exercise from the book “Learning Spark 2nd Edition”, I wrote:

val rnd = scala.util.Random(123)

This resulted in the error:

scala.util.Random.type does not take parameters

What’s going on? Surely, according to the docs I should be able to set the seed.

Turns out, Random is not a case class - it’s a regular class. Regular classes don’t have the apply method defined that allows val myNumberInstance = myNumberCaseClass(123).

Regular classes require the use of new to define a new instance: val myNumberInstance = new myNumberCaseClass(123).

Up to now, I’ve mostly worked with Spark Datasets that involve case classes (in their schema definitions). Case classes are often used for data modeling.