Hi,
I was using rand to simulate a price series, but rand
function returns the same rand no every time on start up,
hence I am not getting truly random price paths. To overcome
this I was thinking of changing the state of the rand series
generator to some random or non repeating variable, one such
variable could be system date and time but don't know how to
do this.
Can some one help with this.
For reference the manual on rand function reads :-
Quote
The sequence of numbers produced by rand is determined
by the internal state of the generator. Setting the
generator to the same fixed state enables you to repeat
computations. Setting the generator to different states
leads to unique computations. It does not, however, improve
statisticalproperties.
Because MATLAB resets the rand state at startup, rand
generates the same sequence of numbers in each session
unless you change the value of the state input.
UnQuote
Subject: Resetting the state of Rand randomly at start up
"Sourav Roy" <souravroy1@rediffmail.com> wrote in message
<g1088r$lfr$1@fred.mathworks.com>...
> Hi,
> I was using rand to simulate a price series, but rand
> function returns the same rand no every time on start up,
> hence I am not getting truly random price paths. To
overcome
> this I was thinking of changing the state of the rand
series
> generator to some random or non repeating variable, one
such
> variable could be system date and time but don't know how
to
> do this.
> Can some one help with this.
>
> For reference the manual on rand function reads :-
>
> Quote
>
> The sequence of numbers produced by rand is determined
> by the internal state of the generator. Setting the
> generator to the same fixed state enables you to repeat
> computations. Setting the generator to different states
> leads to unique computations. It does not, however,
improve
> statisticalproperties.
> Because MATLAB resets the rand state at startup, rand
> generates the same sequence of numbers in each session
> unless you change the value of the state input.
>
> UnQuote
>
>
>
I think
rand('twister',sum(10*clock))
would randomize the seed (at least for the Mersenne twister
mode) for you.
Ken
Subject: Resetting the state of Rand randomly at start up
"Kenneth Eaton" <Kenneth.dot.Eaton@cchmc.dot.org> wrote in
message <g109i4$5t1$1@fred.mathworks.com>...
> I think this is what most people typically do:
>
> rand('state',sum(100.*clock));
>
> Ken
Hi,
Thanks I would try this.
Subject: Resetting the state of Rand randomly at start up
"Sourav Roy" <souravroy1@rediffmail.com> wrote in message
<g1088r$lfr$1@fred.mathworks.com>...
> Hi,
> I was using rand to simulate a price series, but rand
> function returns the same rand no every time on start up,
> hence I am not getting truly random price paths. To
overcome
> this I was thinking of changing the state of the rand
series
> generator to some random or non repeating variable, one
such
> variable could be system date and time but don't know how
to
> do this.
> Can some one help with this.
>
> For reference the manual on rand function reads :-
>
> Quote
>
> The sequence of numbers produced by rand is determined
> by the internal state of the generator. Setting the
> generator to the same fixed state enables you to repeat
> computations. Setting the generator to different states
> leads to unique computations. It does not, however,
improve
> statisticalproperties.
> Because MATLAB resets the rand state at startup, rand
> generates the same sequence of numbers in each session
> unless you change the value of the state input.
>
> UnQuote
>
>
>
Here is the best method for avoiding this behavior. Create
a file called startup.m in the directory MATLAB starts up
in. Within startup.m enter the code:
What this does is automatically saves your random state
whenever you close MATLAB then automatically reloads that
state when your restart MATLAB. This will esentially "turn
off" MATLAB's behavior of resetting it's random state at
startup.
There is nothing significantly wrong with the "rand
('twister',sum(10*clock))" method, but the method I mention
is cleaner and more effectively ensures your random state
doesn't get "polluted".
Note: The startup.m file is automatically run by MATLAB on
startup. Also, the finish.m file is automatically run by
MATLAB on quitting. You can put any code in these files
you want to have automatically run.
Subject: Resetting the state of Rand randomly at start up
On May 21, 12:57=A0am, "Sourav Roy" <souravr...@rediffmail.com> wrote:
> "Kenneth Eaton" <Kenneth.dot.Ea...@cchmc.dot.org> wrote in
> message <g109i4$5t...@fred.mathworks.com>...
>
> > I think this is what most people typically do:
>
> > rand('state',sum(100.*clock));
>
> > Ken
>
> Hi,
> Thanks I would try this.
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.