All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.jeroenr.tepkin.util.Randomizer.scala Maven / Gradle / Ivy

The newest version!
package com.github.jeroenr.tepkin.util

import java.util.concurrent.ThreadLocalRandom

trait Randomizer {

  def random: ThreadLocalRandom = ThreadLocalRandom.current()

  def randomString(alphabet: String)(n: Int): String = {
    Stream.continually(random.nextInt(alphabet.size)).map(alphabet).take(n).mkString
  }

  def randomString(n: Int): String = {
    randomString {
      """!"#$%&'()*+-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"""
    }(n)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy