function randomAddress = helperBLEGenerateRandomDeviceAddress
%helperBLEGenerateRandomDeviceAddress Generates a random device address in
%hexadecimal format

%   Copyright 2018 The MathWorks, Inc.

%#codegen

% Generate random part
randomPart = randi([0 1], 1, 46);

% Random part should not contain all zeros or all ones
while((nnz(randomPart == ones(1, 46)) == 46) || ...
    (nnz(randomPart == zeros(1, 46)) == 46))
  randomPart = randi([0 1], 1, 46);
end

% Generate a 6-octet random address as specified in Bluetooth Core
% Specification v5.0 | Vol 6, Part B, Section 1.3.2
randomAddress = dec2hex(bi2de([randomPart 1 1]), 12);
end