Here is my trick:
case class MyBool(door: Boolean = Random.nextBoolean)
You will be able to create a new instance of MyBool with a specific door value, for example:
val x1 = MyBool() // random door val x2 = MyBool(true) // door set explicitly
Since there can only be two different door values, it would be advisable to use static objects, for example:
sealed trait MyBool { def door:Boolean } object MyBool { case object True extends MyBool { def door = true } case object False extends MyBool { def door = false } def apply:MyBool = if(Random.nextBoolean) True else False }
Using:
val x1 = MyBool()
Madoc
source share