title: Make a random mac address generator generate just unicast macs
body: <p>This is my simple mac address generator:</p>
  
  <pre><code>private String randomMACAddress(){
      Random rand = new Random();
      byte[] macAddr = new byte[6];
      rand.nextBytes(macAddr);
  
      StringBuilder sb = new StringBuilder(18);
      for(byte b : macAddr){
          if(sb.length() &gt; 0){
              sb.append(":");
          }else{ //first byte, we need to set some options
              b = (byte)(b | (byte)(0x01 &lt;&lt; 6)); //locally adminstrated
              b = (byte)(b | (byte)(0x00 &lt;&lt; 7)); //unicast
  
          }
          sb.append(String.format("%02x", b));
      }
  
  
      return sb.toString();
  }
  </code></pre>
  
  <p>Note how I set and unset bits to make so it generates unicast macs.
  However it doesn't work and my automated program which accepts mac addresses returns me an error because "this mac address is multicast".</p>
  
  <p>What am I doing wrong?</p>