Choose Language Hide Translation Bar
Occasional Contributor

## Can I set the random seed for random uniform function?

I try to generate a constant random number everytime I run the script. Is there anyway to do that?

1 ACCEPTED SOLUTION

Accepted Solutions
Staff

## Re: Can I set the random seed for random uniform function?

Take a look at 'RandomReset()':

``````Names Default To Here( 1 );

nr = 10;
nc = 10;
mat = J(nr, nc, .);

for (c=1, c<=nc, c++,
Random Reset( 1 );
mat[0,c] = J(nr, 1, RandomUniform());
);
dt1 = AsTable(mat);
dt1 << setName("Columns the same");

for (c=1, c<=nc, c++,
Random Reset( 666 );
mat[0,c] = J(nr, 1, RandomUniform());
);
dt2 = AsTable(mat);dt2 << setName("Columns the same");``````

2 REPLIES 2
Staff

## Re: Can I set the random seed for random uniform function?

Take a look at 'RandomReset()':

``````Names Default To Here( 1 );

nr = 10;
nc = 10;
mat = J(nr, nc, .);

for (c=1, c<=nc, c++,
Random Reset( 1 );
mat[0,c] = J(nr, 1, RandomUniform());
);
dt1 = AsTable(mat);
dt1 << setName("Columns the same");

for (c=1, c<=nc, c++,
Random Reset( 666 );
mat[0,c] = J(nr, 1, RandomUniform());
);
dt2 = AsTable(mat);dt2 << setName("Columns the same");``````

Highlighted
Occasional Contributor

## Re: Can I set the random seed for random uniform function?

Thank you! Random Reset() work.