Created
July 27, 2023 09:04
-
-
Save Amerousful/6c02315dafd1f160972468830f46868a to your computer and use it in GitHub Desktop.
Scala, generate random IPv4
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.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