setrandstate.m 471 B

123456789101112131415161718192021222324252627
  1. function setrandstate(flag)
  2. % function setrandstate(flag)
  3. %
  4. % <flag> (optional) is
  5. % 0 means seed to 0
  6. % 1 means seed to sum(100*clock)
  7. % {N} means seed to N
  8. % default: 1.
  9. %
  10. % induce randomness by setting the state of rand and randn.
  11. %
  12. % example:
  13. % setrandstate;
  14. if ~exist('flag','var') || isempty(flag)
  15. flag = 1;
  16. end
  17. if iscell(flag)
  18. seed0 = flag{1};
  19. elseif flag==0
  20. seed0 = 0;
  21. else
  22. seed0 = sum(100*clock);
  23. end
  24. rand('state',seed0);
  25. randn('state',seed0);