I was trying to run some Monte-Carlo simulations and if I used:

rng(seed, 'Twister');

For some reason I would get "Option Values Can not be Negative" errors in the blsimpv function, but if I just use the rand (seed) function, the problem seems to be OK (having everything else the same).

My question is, aren't both of them the similar function? (i.e., generate a whole bunch of random numbers). If so, why is one giving me issues and the other is OK?

I post this is Quant since this is related to the implementation of quant models, hope that is OK.

Thanks in advance!

  • $\begingroup$ From the documentation: Calling rand with an integer input n will generate an n-by-n matrix. The integer does not seed the random number generator! $\endgroup$ – chrisaycock Mar 21 '13 at 12:52
  • $\begingroup$ Ah...so I just so happened to use an integral value as a seed when using rand, but I guess it is completely wrong! Sorry, MATLAB noob here :) $\endgroup$ – AZhu Mar 21 '13 at 13:41
  • $\begingroup$ When I try to use 'rng' in my script, I get error - "??? Undefined function or method 'rng' for input arguments of type 'char'." I have MATLAB R2010a installed in my system. What should I do? $\endgroup$ – Prasan Dutt Jun 10 '14 at 10:23

No, rng does not do the same as rand. rng sets the seed for the random number generator and rand generates random numbers. Also it can be seen in documentation that the rng function only accepts positive integers. Usually random number generator algorithms start with integers for the seed. For various examples: C random function takes the system clock as seed as it does Minecraft's world generator.




  • $\begingroup$ Thanks, I think I was confused with the docs, thanks for pointing things out. $\endgroup$ – AZhu Mar 21 '13 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.