cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-215803%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%A6%82%E4%BD%95%E5%B0%87%E9%9A%A8%E6%A9%9F%E7%A8%AE%E5%AD%90%E8%A8%AD%E7%BD%AE%E7%82%BA%E9%9A%A8%E6%A9%9F%E7%B4%A2%E5%BC%95%E5%87%BD%E6%95%B8%EF%BC%9F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-215803%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E6%88%91%E4%BD%BF%E7%94%A8%E9%9A%A8%E6%A9%9F%E7%B4%A2%E5%BC%95%E7%94%9F%E6%88%90%E9%9A%A8%E6%A9%9F%E6%95%B8%E7%9F%A9%E9%99%A3%E3%80%82%20%E4%BD%86%E6%98%AF%EF%BC%8C%E6%88%91%E5%B8%8C%E6%9C%9B%E6%AF%8F%E6%AC%A1%E9%81%8B%E8%A1%8C%E8%85%B3%E6%9C%AC%E6%99%82%E9%83%BD%E6%9C%89%E7%9B%B8%E5%90%8C%E7%9A%84%E9%9A%A8%E6%A9%9F%E6%95%B8%E9%9B%86%E3%80%82%20%E6%88%91%E5%8F%AF%E4%BB%A5%E7%82%BA%E9%9A%A8%E6%A9%9F%E7%B4%A2%E5%BC%95%E5%87%BD%E6%95%B8%E8%A8%AD%E7%BD%AE%E9%9A%A8%E6%A9%9F%E7%A8%AE%E5%AD%90%E5%97%8E%EF%BC%9F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-216230%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E5%A6%82%E4%BD%95%E5%B0%87%E9%9A%A8%E6%A9%9F%E7%A8%AE%E5%AD%90%E8%A8%AD%E7%BD%AE%E7%82%BA%E9%9A%A8%E6%A9%9F%E7%B4%A2%E5%BC%95%E5%87%BD%E6%95%B8%EF%BC%9F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-216230%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E7%95%B6%E6%88%91%E8%AA%AA%E6%B2%92%E6%9C%89%E8%BE%A6%E6%B3%95%E7%82%BA%20Random%20Index()%20%E8%A8%AD%E7%BD%AE%E7%A8%AE%E5%AD%90%E6%99%82%EF%BC%8C%E6%88%91%E6%98%AF%E4%B8%8D%E6%AD%A3%E7%A2%BA%E7%9A%84%EF%BC%9B%20Random%20Reset()%20%E5%87%BD%E6%95%B8%E5%B0%87%E5%AE%8C%E6%88%90%E9%80%99%E9%A0%85%E5%B7%A5%E4%BD%9C%3C%2FP%3E%0A%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0A%0ARandom%20Reset(%201%20)%3B%0Ax%3Drandom%20index(100%2C%2010)%3B%0Ashow(x)%3B%0ARandom%20Reset(%201%20)%3B%0Ax%3Drandom%20index(100%2C%2010)%3B%0Ashow(x)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-215812%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E5%A6%82%E4%BD%95%E5%B0%87%E9%9A%A8%E6%A9%9F%E7%A8%AE%E5%AD%90%E8%A8%AD%E7%BD%AE%E7%82%BA%E9%9A%A8%E6%A9%9F%E7%B4%A2%E5%BC%95%E5%87%B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%82%3C%2FSTRIKE%3E%3C%2FP%3E%0A%3CPRE%3E%3CSTRIKE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Ex%3Drandom%20index(100%2C%2010)%3B%0Ashow(x)%3B%0Asave%20text%20file(%22%24TEMP%2Frandom.txt%22%2C%20char(x))%3B%0Ax%3D%5B%5D%3B%0Ashow(x)%3B%0Ax%3Dparse(load%20text%20file(%22%24TEMP%2Frandom.txt%22))%3B%0Ashow(x)%3B%0A%3C%2FCODE%3E%3C%2FSTRIKE%3E%3C%2FPRE%3E%0A%3CP%3E%3CSTRIKE%3E%E6%82%A8%E9%82%84%E5%8F%AF%E4%BB%A5%E5%89%B5%E5%BB%BA%E4%B8%80%E5%80%8B%E5%8C%85%E5%90%AB%E5%88%97%E4%B8%AD%E7%9F%A9%E9%99%A3%E5%80%BC%E7%9A%84%E6%95%B8%E6%93%9A%E8%A1%A8%EF%BC%8C%E4%BF%9D%E5%AD%98%E6%95%B8%E6%93%9A%E8%A1%A8%E3%80%82%E7%84%B6%E5%BE%8C%E6%A0%B9%E6%93%9A%E9%9C%80%E8%A6%81%E6%89%93%E9%96%8B%E4%BF%9D%E5%AD%98%E7%9A%84%E8%A1%A8%E4%B8%A6%E5%B0%87%E5%88%97%E4%B8%AD%E7%9A%84%E5%80%BC%E8%AE%80%E5%85%A5%E7%9F%A9%E9%99%A3%E3%80%82%3C%2FSTRIKE%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-215810%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%E5%9B%9E%E5%A4%8D%EF%BC%9A%E5%A6%82%E4%BD%95%E5%B0%87%E9%9A%A8%E6%A9%9F%E7%A8%AE%E5%AD%90%E8%A8%AD%E7%BD%AE%E7%82%BA%E9%9A%A8%E6%A9%9F%E7%B4%A2%E5%BC%95%E5%87%BD%E6%95%B8%EF%BC%9F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-215810%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%E6%89%BE%E5%88%B0%E4%B8%80%E5%80%8B%E6%8F%92%E4%BB%B6%EF%BC%9A%3CA%20href%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2FJMP-Add-Ins%2FRandom-Seed-Reset%2Fta-p%2F21973%22%20target%3D%22_blank%22%3E%20https%3A%2F%2Fcommunity.jmp.com%2Ft5%2FJMP-Add-Ins%2FRandom-Seed-Reset%2Fta-p%2F21973%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%E5%B0%8D%E6%96%BC%E7%B0%A1%E5%96%AE%E5%80%BC%EF%BC%9A%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3ENames%20Default%20To%20Here(%201%20)%3B%0ARandom%20Reset(%201%20)%3B%0ARandom%20Normal()%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%E5%B0%8D%E6%96%BC%E4%B8%80%E5%80%8B%E5%B0%8D%E8%B1%A1%EF%BC%9A%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Eobj%20%26lt%3B%26lt%3B%20Set%20Seed(%201111%20)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%E5%B0%8D%E6%96%BC%E4%B8%80%E5%80%8B%E5%B9%B3%E5%8F%B0%EF%BC%9A%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Edt%20%3D%20Open(%20%22%24SAMPLE_DATA%2FBoston%20Housing.jmp%22%20)%3B%0Aobj%20%3D%20Partition(%0A%20Y(%20%3Achas%20)%2C%0A%20X(%20%3Acrim%2C%20%3Azn%2C%20%3Aindus%2C%20%3Amvalue%2C%20%3Anox%2C%20%3Arooms%2C%20%3Aage%2C%20%3Adistance%2C%20%3Aradial%20)%2C%0A%20Method(%20%22Bootstrap%20Forest%22%20)%2C%0A%20Set%20Random%20Seed(%201234%20)%2C%0A%20Go%0A)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%E5%9C%A8%E8%85%B3%E6%9C%AC%E7%B4%A2%E5%BC%95%E4%B8%AD%E5%98%97%E8%A9%A6%E9%9A%A8%E6%A9%9F%E7%A8%AE%E5%AD%90%E4%BB%A5%E7%8D%B2%E5%8F%96%E6%9B%B4%E5%A4%9A%E4%BF%A1%E6%81%AF%EF%BC%9A%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
Shunee
Level I

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
txnelson
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

View solution in original post

3 REPLIES 3
Mauro_Gerber
Level IV

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

Found an addin:  https://community.jmp.com/t5/JMP-Add-Ins/Random-Seed-Reset/ta-p/21973

 

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:

"I thought about our dilemma, and I came up with a solution that I honestly think works out best for one of both of us"
- GLaDOS
txnelson
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);
x=parse(load text file("$TEMP/random.txt"));
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
txnelson
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

Recommended Articles