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:
Seed number of 'unifrnd'

Subject: Seed number of 'unifrnd'

From: Liana

Date: 19 Apr, 2011 00:36:06

Message: 1 of 5

Hello,

I'm using 'unifrnd' to generate uniformly distributed random numbers. The question is if I can define a seed number for 'unifrnd' in order to generate the same random numbers sequence.

Thanks.

Subject: Seed number of 'unifrnd'

From: Liana

Date: 19 Apr, 2011 01:32:04

Message: 2 of 5

I found out that it's possible to define seed numbers for 'randn' (normal distribution) - http://www.mathworks.com/help/techdoc/math/bsn94u0-1.html
Is there the same thing for 'unifrnd'?
Thx.

"Liana" wrote in message <ioildl$bbs$1@fred.mathworks.com>...
> Hello,
>
> I'm using 'unifrnd' to generate uniformly distributed random numbers. The question is if I can define a seed number for 'unifrnd' in order to generate the same random numbers sequence.
>
> Thanks.

Subject: Seed number of 'unifrnd'

From: Liana

Date: 19 Apr, 2011 01:43:04

Message: 3 of 5

I guess I found the answer:

rand('state', 0); % use before 'unifrnd'
unifrnd...

"Liana" wrote in message <ioiomk$3kh$1@fred.mathworks.com>...
> I found out that it's possible to define seed numbers for 'randn' (normal distribution) - http://www.mathworks.com/help/techdoc/math/bsn94u0-1.html
> Is there the same thing for 'unifrnd'?
> Thx.
>
> "Liana" wrote in message <ioildl$bbs$1@fred.mathworks.com>...
> > Hello,
> >
> > I'm using 'unifrnd' to generate uniformly distributed random numbers. The question is if I can define a seed number for 'unifrnd' in order to generate the same random numbers sequence.
> >
> > Thanks.

Subject: Seed number of 'unifrnd'

From: Wayne King

Date: 19 Apr, 2011 04:39:08

Message: 4 of 5

"Liana" wrote in message <ioipb8$d7i$1@fred.mathworks.com>...
> I guess I found the answer:
>
> rand('state', 0); % use before 'unifrnd'
> unifrnd...
>
> "Liana" wrote in message <ioiomk$3kh$1@fred.mathworks.com>...
> > I found out that it's possible to define seed numbers for 'randn' (normal distribution) - http://www.mathworks.com/help/techdoc/math/bsn94u0-1.html
> > Is there the same thing for 'unifrnd'?
> > Thx.
> >
> > "Liana" wrote in message <ioildl$bbs$1@fred.mathworks.com>...
> > > Hello,
> > >
> > > I'm using 'unifrnd' to generate uniformly distributed random numbers. The question is if I can define a seed number for 'unifrnd' in order to generate the same random numbers sequence.
> > >
> > > Thanks.

Hi Liana, Yes, you are correct. Just seed the random number generator before calling unifrnd.
In R2011a, there is a new function rng, that makes controlling the random number generator simplier.

rng(1e3)
x = unifrnd(-1,1,10,1)

rng(1e3)
y = unifrnd(-1,1,10,1)

x and y are the same random sequence.

Wayne

Subject: Seed number of 'unifrnd'

From: Liana

Date: 19 Apr, 2011 05:07:03

Message: 5 of 5

Thank you, Wayne!

"Wayne King" <wmkingty@gmail.com> wrote in message <ioj3lc$mju$1@fred.mathworks.com>...
> "Liana" wrote in message <ioipb8$d7i$1@fred.mathworks.com>...
> > I guess I found the answer:
> >
> > rand('state', 0); % use before 'unifrnd'
> > unifrnd...
> >
> > "Liana" wrote in message <ioiomk$3kh$1@fred.mathworks.com>...
> > > I found out that it's possible to define seed numbers for 'randn' (normal distribution) - http://www.mathworks.com/help/techdoc/math/bsn94u0-1.html
> > > Is there the same thing for 'unifrnd'?
> > > Thx.
> > >
> > > "Liana" wrote in message <ioildl$bbs$1@fred.mathworks.com>...
> > > > Hello,
> > > >
> > > > I'm using 'unifrnd' to generate uniformly distributed random numbers. The question is if I can define a seed number for 'unifrnd' in order to generate the same random numbers sequence.
> > > >
> > > > Thanks.
>
> Hi Liana, Yes, you are correct. Just seed the random number generator before calling unifrnd.
> In R2011a, there is a new function rng, that makes controlling the random number generator simplier.
>
> rng(1e3)
> x = unifrnd(-1,1,10,1)
>
> rng(1e3)
> y = unifrnd(-1,1,10,1)
>
> x and y are the same random sequence.
>
> Wayne

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