Skip to content

Instantly share code, notes, and snippets.

@Amerousful
Created July 27, 2023 09:04
Show Gist options
  • Save Amerousful/6c02315dafd1f160972468830f46868a to your computer and use it in GitHub Desktop.
Save Amerousful/6c02315dafd1f160972468830f46868a to your computer and use it in GitHub Desktop.
Scala, generate random IPv4
import java.util.concurrent.ThreadLocalRandom
def random(max: Int): Int = {
ThreadLocalRandom.current().nextInt(max + 1)
}
def generateIpV4():String =
(Seq.fill(3)(random(255)) ++ Seq(random(254))).mkString(".")
println(generateIpV4())
// 217.0.184.225
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment