Files
native-mdns/src/commonMain/kotlin/cn/rtast/nmdns/util/mac.kt
T

20 lines
422 B
Kotlin
Raw Normal View History

2025-09-29 01:43:17 +08:00
/*
* Copyright © 2025 RTAkland
* Author: RTAkland
* Date: 9/29/25
*/
2026-03-14 00:12:46 +08:00
package cn.rtast.nmdns.util
2025-09-29 01:43:17 +08:00
import kotlin.experimental.ExperimentalNativeApi
import kotlin.random.Random
2025-09-29 01:43:17 +08:00
2025-09-29 06:30:39 +08:00
/**
* generate random mac address
2025-09-29 06:30:39 +08:00
*/
@OptIn(ExperimentalNativeApi::class)
public fun randomMacAddress(): String {
val bytes = ByteArray(6) { Random.nextInt(0, 256).toByte() }
return bytes.joinToString(":") { it.toHexString() }
}