BookmarkSubscribe
Choose Language Hide Translation Bar
Highlighted
Occasional Contributor

## How can I set random seed into Random Index function?

I use Random Index to generate a marix of random numbers. However, I would like to have same set of random numbers everytime I run the script. Can I set random seed for Random Index function?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: How can I set random seed into Random Index function?

I was incorrect when I stated that there isn't a way to set the seed for a Random Index();  The Random Reset() function will do the job

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

Random Reset( 1 );
x=random index(100, 10);
show(x);
Random Reset( 1 );
x=random index(100, 10);
show(x);``````
Jim
3 REPLIES 3
Occasional Contributor

## Re: How can I set random seed into Random Index function?

For simple values:

``````Names Default To Here( 1 );
Random Reset( 1 );
Random Normal();``````

For an object:

``obj << Set Seed( 1111 );``

For a platform:

``````dt = Open( "\$SAMPLE_DATA/Boston Housing.jmp" );
obj = Partition(
Y( :chas ),
X( :crim, :zn, :indus, :mvalue, :nox, :rooms, :age, :distance, :radial ),
Method( "Bootstrap Forest" ),
Set Random Seed( 1234 ),
Go
);``````

Try Random Seed in the scritping index for further info:

Super User

## Re: How can I set random seed into Random Index function?

I do not believe that you can set the seed for Random Index.  However, you can do a one time generation of the matrix you need and then save it to a text file.  You can then read in the matrix from the text file at the beginning of your script, and set the matrix that way.  Here is a simple illustration of creating a matrix, saving it to a text file, and then how to retrieve it.

``````x=random index(100, 10);
show(x);
save text file("\$TEMP/random.txt", char(x));
x=[];
show(x);
show(x);
``````

You could also create a data table with the matrix values in a column, save the data table.  Then as needed open the saved table and read the values from the column into a matrix.

Jim
Super User

## Re: How can I set random seed into Random Index function?

I was incorrect when I stated that there isn't a way to set the seed for a Random Index();  The Random Reset() function will do the job

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

Random Reset( 1 );
x=random index(100, 10);
show(x);
Random Reset( 1 );
x=random index(100, 10);
show(x);``````
Jim