% GET_RANDOM_UNIT returns a random unit object, with random unit and random
% prefix (if the unit is different from '')
%
% CALL:   u = get_test_ples
%
% OUTPUTS: u  - a unit object with random unit and prefix
%
% VERSION: $Id: get_random_unit.m,v 1.2 2010/05/05 04:21:52 mauro Exp $
%
function u = get_random_unit(varargin)
  unit_list = unit.supportedUnits;
  prefix_list = unit.supportedPrefixes;
  
  u = cell2mat(utils.math.randelement(unit_list,1));
  
  pref = true;
  if nargin
    switch varargin{1}
      case {'nopref', 'noprefix', 'no_pref', 'no_prefix'}
        pref = false;
      otherwise
    end
  end
  
  % Add a prefix only if the unit is different from ''
  if pref && ~isempty(u) && ~strcmpi(u, '')
    u = unit([cell2mat(utils.math.randelement(prefix_list,1)) u]);
  else
    u = unit(u);
  end
  
end