function opts = callOptsFromRandStream(rs)
% Helper to setup appropriate call options for a tall internal API call
% that needs random numbers.
%
% opts = callOptsFromRandStream() or opts = callOptsFromRandStream([])
% returns a default PartitionedArrayOptions options structure.
%
% opts = callOptsFromRandStream(rs) returns a call options structure with a
% RandStream factory based on the supplied RandStream RS (which must
% support streams and substreams).
%
% Example (from datasample):
% [S,nS,chunkSizes] = partitionfun( internal.stats.bigdata.callOptsFromRandstream(rs), ...
%    @(info,x) constantRandSampleFun(info,x,k), data);
%
% See also: matlab.bigdata.internal.PartitionedArrayOptions.

% Copyright 2017 The MathWorks, Inc.

if nargin<1 || isempty(rs)
    opts = matlab.bigdata.internal.PartitionedArrayOptions('RequiresRandState', true);
else
    % Custom RandStream
    opts = matlab.bigdata.internal.PartitionedArrayOptions('RequiresRandState', true);
    opts.RandStreamFactory = matlab.bigdata.internal.RandStreamFactory(rs);
end
end
