Take the 2-minute tour ×
Quantitative Finance Stack Exchange is a question and answer site for finance professionals and academics. It's 100% free, no registration required.

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!

share|improve this question
    
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! –  chrisaycock Mar 21 '13 at 12:52
    
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 :) –  AZhu Mar 21 '13 at 13:41
    
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? –  Prasan Dutt Jun 10 at 10:23

1 Answer 1

up vote 3 down vote accepted

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.

Doc:

rnd

rand

share|improve this answer
    
Thanks, I think I was confused with the docs, thanks for pointing things out. –  AZhu Mar 21 '13 at 13:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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