Skip to content

Instantly share code, notes, and snippets.

@mahata
Last active June 5, 2021 20:38
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahata/4145905 to your computer and use it in GitHub Desktop.
Save mahata/4145905 to your computer and use it in GitHub Desktop.
random ascii string generator in Scala
object randomSample {
def randomString(length: Int) = Stream.continually(util.Random.nextPrintableChar) take length mkString
}
println(randomSample.randomString(64))
@ozeebee
Copy link

ozeebee commented Sep 9, 2015

even shorter:

def randomString(length: Int) = scala.util.Random.alphanumeric.take(length).mkString

@vpipkt
Copy link

vpipkt commented Oct 26, 2016

gratzie

@piggybox
Copy link

Nice

@liu-peiwen
Copy link

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment