Created
January 27, 2018 22:48
-
-
Save zyuiop/36dd008dabb1b794590855094f736291 to your computer and use it in GitHub Desktop.
A joke I made to generate a fake CSV listing of notes mapped to student names/scipers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.PrintWriter | |
import scala.io.Source | |
import scala.util.Random | |
/** | |
* @author Louis Vialar | |
*/ | |
object NotesRandomizer { | |
val namesAndScipers: List[String] = Source.fromFile("names.csv").getLines().map(a => a.split(";")(0)).toList | |
val notes: List[Double] = Source.fromFile("notes.csv").getLines().map(_.split(";")(2).toDouble).toList | |
val shuffled: List[Double] = Random.shuffle(notes).map(v => { | |
val change = Random.nextInt(11) - 5 | |
Math.abs(v + change) | |
}) | |
val outArray: List[(String, Double)] = namesAndScipers zip shuffled | |
val str: String = outArray map { case (name, note) => name + ";" + note } mkString "\n" | |
def main(args: Array[String]): Unit = { | |
println(str) | |
new PrintWriter("output.csv") { write(str); close() } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment