1function private_stream = spqr_repeatable (seed)
2%SPQR_REPEATABLE ensure repeatable results, or use the default random stream.
3% Uses RandStream for repeatable results, which is not available on MATLAB 7.6
4% or earlier (R2008a).  For that version of MATLAB (or earlier), the seed is
5% ignored and the default random stream is always used.
6% Not user-callable.
7
8% Copyright 2012, Leslie Foster and Timothy A Davis
9
10% Since this code is called very often, use 'version', which is perhaps 100
11% times faster than 'verLessThan'.
12v = sscanf (version, '%d.%d.%d') ;
13v = 10.^(0:-1:-(length(v)-1)) * v ;
14
15if (v < 7.7)
16    % MATLAB 7.6 and earlier do not have RandStream, so spqr_rank ignores
17    % the opts.repeatable option and just uses the default random stream.
18    private_stream = [ ] ;
19elseif (seed == 1)
20    % use a new strearm with the default random seed
21    private_stream = RandStream ('mt19937ar') ;
22elseif (seed > 1)
23    % use a new stream with a specific random seed
24    private_stream = RandStream ('mt19937ar', 'seed', seed) ;
25else
26    % do not use the private stream
27    private_stream = [ ] ;
28end
29
30