Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Help on deprecated rand parameters

Subject: Help on deprecated rand parameters

From: Jeff

Date: 5 Dec, 2009 17:59:03

Message: 1 of 9

Some code that I'm working on has the following line:

rand('state',sum(100*clock))

The editor issues a warning which says "Using character strings to control RAND is deprecated. I need to understand that line, but the help on rand (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randstream.rand.html) does not give any information on the deprecated parms. Does anyone know where I can find info on the deprecated uses? Thanks,
-Jeff

Subject: Help on deprecated rand parameters

From: ImageAnalyst

Date: 5 Dec, 2009 18:12:52

Message: 2 of 9

On Dec 5, 12:59 pm, "Jeff " <spREMOVEHITSjef...@SIGNoptonline.net>
wrote:
> Some code that I'm working on has the following line:
>
> rand('state',sum(100*clock))
>
> The editor issues a warning which says "Using character strings to control RAND is deprecated. I need to understand that line, but the help on rand (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randstream....) does not give any information on the deprecated parms. Does anyone know where I can find info on the deprecated uses? Thanks,
> -Jeff

-----------------------------------------------
How about you just say what you WANT to do and let's go from there?

Most people only have one or two versions on MATLAB on their computer
and may not have a version old enough for you.

Subject: Help on deprecated rand parameters

From: Jeff

Date: 5 Dec, 2009 18:47:03

Message: 3 of 9

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <f705b4ff-7356-4a88-9378-38cf63e27b5a@31g2000vbf.googlegroups.com>...
> On Dec 5, 12:59?pm, "Jeff " <spREMOVEHITSjef...@SIGNoptonline.net>
> wrote:
> > Some code that I'm working on has the following line:
> >
> > rand('state',sum(100*clock))
> >
> > The editor issues a warning which says "Using character strings to control RAND is deprecated. I need to understand that line, but the help on rand (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randstream....) does not give any information on the deprecated parms. Does anyone know where I can find info on the deprecated uses? Thanks,
> > -Jeff
>
> -----------------------------------------------
> How about you just say what you WANT to do and let's go from there?
>
> Most people only have one or two versions on MATLAB on their computer
> and may not have a version old enough for you.

Unfortunately, that is what I want to do. This is a project for school. I have been given the code above and one of the questions is: What role does rand play?

I am to answer that question and then I may have to modify the code (although that's unlikely). I would ask my professor the question, but he is incommunicado this weekend (see what I get by waiting until last minute?) - and he doesn't really answer questions, anyway. That's why I asked the question the way I did.

I am going to modify the program to implement a card counting Monte Carlo simulation. It's true that I probably won't have to modify the randomization line, but I still must answer the question.

Once again, thank you,
-Jeff

Subject: Help on deprecated rand parameters

From: Jeff

Date: 5 Dec, 2009 18:58:03

Message: 4 of 9

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <f705b4ff-7356-4a88-9378-38cf63e27b5a@31g2000vbf.googlegroups.com>...
> On Dec 5, 12:59?pm, "Jeff " <spREMOVEHITSjef...@SIGNoptonline.net>
> wrote:
> > Some code that I'm working on has the following line:
> >
> > rand('state',sum(100*clock))
> >
> > The editor issues a warning which says "Using character strings to control RAND is deprecated. I need to understand that line, but the help on rand (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randstream....) does not give any information on the deprecated parms. Does anyone know where I can find info on the deprecated uses? Thanks,
> > -Jeff
>
> -----------------------------------------------
> How about you just say what you WANT to do and let's go from there?
>
> Most people only have one or two versions on MATLAB on their computer
> and may not have a version old enough for you.

OK, this might be a better answer to your question "what do I want to do?"

The random number generator is used later on in the program like this:

deck = deck(randperm(ncards));

where ncards is a scalar indicating the number of cards in the deck (e.g., 52 if we use just one deck).

Subject: Help on deprecated rand parameters

From: Bruno Luong

Date: 5 Dec, 2009 19:39:03

Message: 5 of 9

I believe the purpose of this line is to make sure the subsequent random generations are differences from run to run. It starts the random *seed* with the current time, so the seeds will never repeated.

Bruno

Subject: Help on deprecated rand parameters

From: Jeff

Date: 5 Dec, 2009 21:12:03

Message: 6 of 9

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <hfecsn$jdq$1@fred.mathworks.com>...
> I believe the purpose of this line is to make sure the subsequent random generations are differences from run to run. It starts the random *seed* with the current time, so the seeds will never repeated.
>
> Bruno

OK, that sounds right. It sounds like this command was replaced by RandStream. I'll read about that and be done in no time :D. Thanks,
-Jeff

Subject: Help on deprecated rand parameters

From: Peter Perkins

Date: 6 Dec, 2009 17:33:12

Message: 7 of 9

Jeff wrote:
> Some code that I'm working on has the following line:
>
> rand('state',sum(100*clock))
>
> The editor issues a warning which says "Using character strings to control RAND is deprecated. I need to understand that line, but the help on rand (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randstream.rand.html) does not give any information on the deprecated parms. Does anyone know where I can find info on the deprecated uses? Thanks,

Jeff, first off, the deprecated syntax continues to work, exactly as it always has. So you can still use it with no harm if you want. It's just that the old syntax was not scalable going forward, and had some quirks in it that tended to confuse people without their even knowing it.

The User Guide has a whole section on RandStream and random number generation, including a section on backwards compatibility. There is not a list of specific "you used to do this, now do this". However, the help does give examples that describe how to do essentially everything that the old syntax allowed.

That line of code, as Bruno says, gives you different values from rand/randn/randi each time you start up MATLAB -- ordinarily, you'd get the same values. The help for rand has this to say, including an example:

>> help rand
 RAND Uniformly distributed pseudorandom numbers.
[snip]
    Compatibility Note: In versions of MATLAB prior to 7.7, you controlled
    the internal state of the random number stream used by RAND by calling
    RAND directly with the 'seed', 'state', or 'twister' keywords. That
    syntax is still supported for backwards compatibility, but is deprecated.
    Beginning in MATLAB 7.7, use the default stream as described in
    RANDSTREAM.
 
    The sequence of numbers produced by RAND is determined by the internal
    state of the uniform pseudorandom number generator that underlies RAND,
    RANDI, and RANDN. Control that default random number stream using its
    properties and methods. See RANDSTREAM for details about the default
    stream.
 
    Resetting the default stream to the same fixed state allows computations
    to be repeated. Setting the stream to different states leads to unique
    computations, however, it does not improve any statistical properties.
    Since MATLAB uses the same state each time it starts up, RAND, RANDN, and
    RANDI will generate the same sequence of numbers in each session unless
    the state is changed.
 
    Examples:

[snip]
       Replace the default stream with a stream whose seed is based on CLOCK,
       so RAND will return different values in different MATLAB sessions.
       NOTE: It is usually not desirable to do this more than once per MATLAB
       session.
          RandStream.setDefaultStream(RandStream('mt19937ar','seed',sum(100*clock)));
          rand(1,5)

and also gives links to the RandStream help page. The syntax you were being nagged about falls under the area of "controlling the random number stream".

Hope this helps.

Subject: Help on deprecated rand parameters

From: Peter Perkins

Date: 6 Dec, 2009 17:36:24

Message: 8 of 9

Bruno Luong wrote:
> I believe the purpose of this line is to make sure the subsequent random generations are differences from run to run. It starts the random *seed* with the current time, so the seeds will never repeated.

Exactly correct. The drawback, and it's not obvious until it's too late, is that unless you save that seed somewhere, you won't ever be able to go back and reproduce the same random values. In many/most cases, that's not a problem but sometimes it is.

Subject: Help on deprecated rand parameters

From: Jeff

Date: 6 Dec, 2009 20:28:05

Message: 9 of 9

Peter Perkins <Peter.Perkins@MathRemoveThisWorks.com> wrote in message <hfgpso$rju$1@fred.mathworks.com>...
> Jeff wrote:
> > Some code that I'm working on has the following line:
> >
> > rand('state',sum(100*clock))
> >
> > The editor issues a warning which says "Using character strings to control RAND is deprecated. I need to understand that line, but the help on rand (http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randstream.rand.html) does not give any information on the deprecated parms. Does anyone know where I can find info on the deprecated uses? Thanks,
>
> Jeff, first off, the deprecated syntax continues to work, exactly as it always has. So you can still use it with no harm if you want. It's just that the old syntax was not scalable going forward, and had some quirks in it that tended to confuse people without their even knowing it.
>
> The User Guide has a whole section on RandStream and random number generation, including a section on backwards compatibility. There is not a list of specific "you used to do this, now do this". However, the help does give examples that describe how to do essentially everything that the old syntax allowed.
>
> That line of code, as Bruno says, gives you different values from rand/randn/randi each time you start up MATLAB -- ordinarily, you'd get the same values. The help for rand has this to say, including an example:
>
> >> help rand
> RAND Uniformly distributed pseudorandom numbers.
> [snip]
> Compatibility Note: In versions of MATLAB prior to 7.7, you controlled
> the internal state of the random number stream used by RAND by calling
> RAND directly with the 'seed', 'state', or 'twister' keywords. That
> syntax is still supported for backwards compatibility, but is deprecated.
> Beginning in MATLAB 7.7, use the default stream as described in
> RANDSTREAM.
>
> The sequence of numbers produced by RAND is determined by the internal
> state of the uniform pseudorandom number generator that underlies RAND,
> RANDI, and RANDN. Control that default random number stream using its
> properties and methods. See RANDSTREAM for details about the default
> stream.
>
> Resetting the default stream to the same fixed state allows computations
> to be repeated. Setting the stream to different states leads to unique
> computations, however, it does not improve any statistical properties.
> Since MATLAB uses the same state each time it starts up, RAND, RANDN, and
> RANDI will generate the same sequence of numbers in each session unless
> the state is changed.
>
> Examples:
>
> [snip]
> Replace the default stream with a stream whose seed is based on CLOCK,
> so RAND will return different values in different MATLAB sessions.
> NOTE: It is usually not desirable to do this more than once per MATLAB
> session.
> RandStream.setDefaultStream(RandStream('mt19937ar','seed',sum(100*clock)));
> rand(1,5)
>
> and also gives links to the RandStream help page. The syntax you were being nagged about falls under the area of "controlling the random number stream".
>
> Hope this helps.

Thanks to both Peter an Bruno. I have enough to answer the question and, if necessary, rewrite the line (actually, I might rewrite it even if it's not necessary, just because I don't like deprecated syntax).

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us