go生成随机mac

hellsam · · 1593 次点击
<a href="/user/buscoop" title="@buscoop">@buscoop</a> 大牛 貌似不对啊。
#3
更多评论
buscoop
纸上得来终觉浅,绝知此事要躬行!
&lt;pre&gt; import ( &#34;crypto/rand&#34; &#34;fmt&#34; ) func main() { buf := make([]byte, 6) _, err := rand.Read(buf) if err != nil { fmt.Println(&#34;error:&#34;, err) return } // Set the local bit buf[0] |= 2 fmt.Printf(&#34;Random MAC address: %02x:%02x:%02x:%02x:%02x:%02x\n&#34;, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]) } &lt;/pre&gt;
#1
buscoop
纸上得来终觉浅,绝知此事要躬行!
``` go import ( &#34;crypto/rand&#34; &#34;fmt&#34; ) func main() { buf := make([]byte, 6) _, err := rand.Read(buf) if err != nil { fmt.Println(&#34;error:&#34;, err) return } // Set the local bit buf[0] |= 2 fmt.Printf(&#34;Random MAC address: %02x:%02x:%02x:%02x:%02x:%02x\n&#34;, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]) } ```
#2