I need lots of random numbers, one per line. The result should be something like this:
24324 24324
4234234 4234234
1310313 1310313
...
So I wrote this spark code (Sorry I'm new to Spark and scala):
import util.Random
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
object RandomIntegerWriter {
def main(args: Array[String]) {
if (args.length < 2) {
System.err.println("Usage: RandomIntegerWriter <num Integers> <outDir>")
System.exit(1)
}
val conf = new SparkConf().setAppName("Spark RandomIntegerWriter")
val spark = new SparkContext(conf)
val distData = spark.parallelize(Seq.fill(args(0).toInt)(Random.nextInt))
distData.saveAsTextFile(args(1))
spark.stop()
}
}
Notes: Now I just want to generate one number per line.
But it seems that when number of numbers gets larger, the program will report an error. Any idea with this piece of code?
Thank you.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…