src/main/scala/robot.scala

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import scala.util.Random.nextInt

object Robot {
  val alphabet = 'A' to 'Z'
  def letters = Stream.continually(alphabet(nextInt(26)))
  def digits = Stream.continually(nextInt(10))

  def generateName = (letters.take(2) ++ digits.take(3)).mkString
}

class Robot {
  private var _name = Robot.generateName
  def name = _name

  def reset() = {
    _name = Robot.generateName
  }
}

@abo64 thinks this looks great

Comments


You're not logged in right now. Please login via GitHub to comment