# Matlab - Differences between rng and rand

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.

-
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

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.
rnd
rand